在一张树形的数据库表中,怎样读取所有的叶子节点啊,过滤非叶子节点的节点数

解决方案 »

  1.   

    用connect by 
    然后使用level伪列
      

  2.   

    用connect by 取出树形结构,用level伪列过滤吗??
    能不能再具体点。
      

  3.   

    with tt 
    as
    (select 1 as id ,0 as pid from dual
    union all
    select 2 as id ,1 as pid from dual
    union all
    select 3 as id ,2 as pid from dual
    union all
    select 4 as id ,3 as pid from dual
    union all
    select 5 as id ,1 as pid from dual
    union all
    select 6 as id ,5 as pid from dual)
    select * from 
    (
    select a.*,level,connect_by_isleaf flg from tt a
    start with id=1
    connect by prior id=pid

    where flg =1
      

  4.   

    select * from tt
    where level>1
    start with id=:id
    connect by prior childid=id