下表为一个树形分类表,我想要得到此表中所有最末端条目(即所有无分类项)
表结构如下:
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,请高手帮忙,谢谢!

解决方案 »

  1.   

    select * from tb a
    where not exists(
        select * from tb 
        where  y_parent = a.y_id)
      

  2.   

    select * from tb a
    where not exists(
        select * from tb 
        where  y_parent = a.y_id)
    tb a 不明白这个是什么意思 !
      

  3.   

    to zjcxc(邹建):非常感谢,谢谢啦!to sfssmiss(遗忘的鸟):这个是别名啊
      

  4.   

    tb a 中的a是tb表的别名