select a.ename 员工名字,b.ename 上级名字,b.职衔,c.所在部门名称
创新互联是一家集网站建设,峨边彝族企业网站建设,峨边彝族品牌网站建设,网站定制,峨边彝族网站建设报价,网络营销,网络优化,峨边彝族网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
from emp a,emp b,dept c where a.mgr=b.empno(+) and a.deptno=c.deptno(+)
简单做了几条数据,我这应该是没问题,只是不知道拿到你那会怎么样,有问题直接回复
测试数据
create table test
(parent_id int,
id int,
is_rp int,
name varchar2(10));
insert into test values (null,1,1,'aa');
insert into test values (1,2,1,'bb');
insert into test values (1,3,2,'cc');
insert into test values (2,4,1,'dd');
insert into test values (3,5,2,'ee');
insert into test values (4,6,2,'ff');
commit;
执行
with t as
(select test.*,level as lv from test
start with id = 6 --这个地方为输入id
connect by prior parent_id=id)
select name from t where exists
(select 1 from
(select is_rp,min(lv) lv from t where is_rp=1 group by is_rp) a
where a.is_rp=t.is_rp and a.lv=t.lv)
你运行一下看看结果
如果是SQL2005以上则可以用CTE递归写法
use tempdb
go
create table #emp
(eid integer not null,
ename varchar(10) not null,
epid integer null,
)
insert into #emp
select 1,'A',5
union all
select 2,'me',3
union all
select 3,'bos',4
union all
select 4,'boss',null
select * from #emp
;with empcte as
(select epid,(select ename from #emp b where b.eid = a.epid) as name from #emp a where ename = 'me'
union all
select b.epid,(select ename from #emp where eid = b.epid) as name from empcte a join #emp b on a.epid = b.eid
)
select * from empcte where epid is not null