;WITH T AS
(
SELECT Id
FROM tb AS A
WHERE
--NOT EXISTS(SELECT * FROM tb WHERE Id = A.ParentId ) AND --加这句条件,就排除自己
A.Id=‘5801CB7F-06DB-46A7-BA97-F0C7CB5D3ADA‘
UNION ALL
SELECT A.Id FROM [tb] AS A JOIN T AS B ON A.ParentId = B.Id
)
SELECT Id FROM T ;
原文地址:https://www.cnblogs.com/jasonlai2016/p/9805916.html
时间: 2024-10-13 10:40:32