>데이터 베이스 >MySQL 튜토리얼 >WITH子句的递归查询

WITH子句的递归查询

WBOY
WBOY원래의
2016-06-07 14:56:421641검색

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으로 문의하세요.