例如:c的上级是b,b的上级是a
    我要查询出a的所有下级,包括b的下级

解决方案 »

  1.   

    跟我的数据库结构有什么关系?就在一个表里..有一个自身id,还有一个上级id两个字段
      

  2.   

    create table tb3 ( id  varchar2(3), name  varchar2(10), p_id varchar2(3),
    constraint pk_tb3id primary key (id));insert into tb3  values ('a','aa','');
    insert into tb3 values ('b','bb','a');
    insert into tb3 values ('c','cc','b');
    commit;
    select t.name from tb3 join (select name,p_id from tb3) t on tb3.id=t.p_id;
    這是版主想要的結果嗎
      

  3.   

    select id from table where parent_id='a' 
    union
    select id from table where parent_id in (select id from table where parent_id='a')
    不知道符合不符合你的要求,当然这个语句速度会慢!
      

  4.   

    这两个语句可以满足你的要求:
    1。select * from tableName start with ID=10  connect by prior parentID = ID
    2。select * from tableName start with parentID =10  connect by prior parentID = ID1为往前找父记录;2为往后找子记录.
      

  5.   

    select id,name,p_id from (select id,name,p_id from test ) a start with p_id = 'a' connect by prior a.id = a.p_id order by p_id;