idTask idParent Description
1 Root
2 1 Parent-1
3 1 Parent-2
4 1 Parent-3
5 1 Parent-4
6 4 Child31
7 4 Child32
8 5 Child41
9 8 Child411
10 8 Child412我需要一个查询来检索记录,
输出
2 1 Parent-1
3 1 Parent-2
6 4 Child31
7 4 Child32
9 8 Child411
10 8 Child412发布于 2017-11-08 15:17:06
如果您指的是树中的叶子,则可以通过自连接表查找没有子行的行,并查找空记录:
SELECT parent.Id
FROM task parent LEFT OUTER JOIN task child on child.idParent= parent.IdTask
WHERE child.IdTask IS NULL发布于 2017-11-08 15:15:53
select * from task t1 where not exists (select 1 from task where idParent = t1.idTask)https://stackoverflow.com/questions/47183139
复制相似问题