且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于过滤记录的SQL查询

更新时间:2023-02-05 16:22:02

你好Vaibhav,



添加递归将是一种方式..



i尝试创建一个避免递归的解决方案,如下所示。


Hello Vaibhav,

Adding a recursion will be one way..

i tried to create a solution which will avoid recursion as below

SELECT DISTINCT A.* from Demo A LEFT JOIN DEMO B ON A.GroupID !=  B.ParentGroupId
WHERE ISNULL(A.ParentGroupId,-99) != 6 AND ISNULL(A.ParentGroupId,-99) NOT IN ( SELECT DISTINCT A.GroupID from Demo A LEFT JOIN DEMO B ON A.GroupID =  B.ParentGroupId WHERE B.ParentGroupId !=6)





希望它能解决你的问题(我知道它看起来很奇怪,但为了避免递归它可以使用)



如果这对您来说是正确的,请将其标记为答案



Hope that it should solve your problem(i know it looks weird but for sake of avoiding recursion it can be used)

Please mark it as answer if this seems correct to you