我有这两个查询,它们返回相同的输出:
;WITH reta
AS (SELECT *
FROM TEST r
WHERE Group_ID = 2
UNION ALL
SELECT t.*
FROM TEST t
INNER JOIN reta r ON t.Parent_ID = r.Group_ID)
SELECT *
FROM reta order by 1;
AND
select * from TEST t
left outer join TEST t1 on t.Parent_ID=t1.Group_ID
where t.Group_ID >= 2
order by 1
但是,如果我将group_ID从2更改为3,则会返回不同的结果。我上面的查询返回2行,但我的第二次查询返回103行。我发现很难匹配两个查询的输出。