Home > Database > Mysql Tutorial > body text

WITH子句的递归查询

WBOY
Release: 2016-06-07 14:56:42
Original
1620 people have browsed it

WITH子句的递归查询 无 WITH RPL AS(SELECT FId,FNumber,FName,FManagerIdFROM T_PersonWHERE FManagerId IS NOT NULL)SELECT FId,FNumber,FName,FManagerId FROM RPL WITH RPL(FId,FNumber,FName,FManagerId) AS(SELECT FOOT.FId,ROOT.FNumber,ROOT.FName,RO

WITH子句的递归查询
WITH RPL AS
(
SELECT FId,FNumber,FName,FManagerId
FROM T_Person
WHERE FManagerId IS NOT NULL
)
SELECT FId,FNumber,FName,FManagerId FROM RPL
Copy after login
WITH RPL(FId,FNumber,FName,FManagerId) AS
(
SELECT FOOT.FId,ROOT.FNumber,ROOT.FName,ROOT.FManagerId
FROM T_Person ROOT
WHERE ROOT.FId='00001'
UNION ALL
SELECT CHILD.FId,CHILD.FNumber,CHILD.FName,CHILE.FManagerId
FROM RPL PARENT,T_Person CHILD
WHERE PARENT.FId=CHILD.FManagerId
)
SELECT DISTINCT FId,FNumber,FName,FManagerId
FROM RPL
ORDER BY FManageId,FId,FNumber,FName
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template