标签:sts sele sql with 排除 exist union all 递归查询 select
;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 ;
标签:sts sele sql with 排除 exist union all 递归查询 select
原文地址:https://www.cnblogs.com/jasonlai2016/p/9805916.html