首頁 >資料庫 >mysql教程 >WITH子句的递归查询

WITH子句的递归查询

WBOY
WBOY原創
2016-06-07 14:56:421634瀏覽

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
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
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn