下表为一个树形分类表,我想要得到此表中所有最末端条目(即所有无分类项)
表结构如下:
y_id y_name y_parent y_depth
1 a 0 1
2 b 1 2
3 c 1 2
4 d 2 3
5 e 2 3
6 f 3 3
7 g 3 3
8 h 4 4
9 i 5 4
10 j 7 4通过查询,应该得到y_id为:5,8,9,10
怎么写SQL,请高手帮忙,谢谢!
表结构如下:
y_id y_name y_parent y_depth
1 a 0 1
2 b 1 2
3 c 1 2
4 d 2 3
5 e 2 3
6 f 3 3
7 g 3 3
8 h 4 4
9 i 5 4
10 j 7 4通过查询,应该得到y_id为:5,8,9,10
怎么写SQL,请高手帮忙,谢谢!
where not exists(
select * from tb
where y_parent = a.y_id)
where not exists(
select * from tb
where y_parent = a.y_id)
tb a 不明白这个是什么意思 !