查询父级部门最后一步遇到的问题
查询用户表时显示的部门名称是从上到下所有部门的名称,如人员属于"公司领导",则显示"XX分公司/公司领导"
select u.*,(select aname from ( select SYS_CONNECT_BY_PATH(Name,'/') aname from department start wITh id=u.Deptid connect by prior pid=id order by id asc ) c where rownum<=1) deptname from accounts_user u
经过百度,里面查询父级部门的select aname from ( select SYS_CONNECT_BY_PATH(Name,'/') aname from department start wITh id=83 connect by prior pid=id order by id asc ) c where rownum<=1) deptname 这一截肯定没问题,但是总不能让ID=83吧,然后仍到accounts_user u里面,让id=u.Deptid ,果断出错,不认识u.
求助该怎么写.
------解决方案--------------------自己百度解决了...
select u.*,(select aname from ( select SYS_CONNECT_BY_PATH(Name,'/') aname,id from department connect by prior id=pid start wITh pid=0 ) c where c.id=u.deptid and rownum<=1) deptname from accounts_user u