请教个case 问题,分不多,还请大家海涵.
再来问个吧.
create employee
(eid int,ename varchar(50))
go
create relation
(eid int,bid int)
go
insert employee
select 1,a unoin all
select 2,a unoin all
select 3,a
go
insert relation
select 2,1 unoin all
select 1,3
go
说明:relation表里就是eid的关系.比如2,1 表示:1是2的领导,1,3表示3是1的领导 ,3没有,表示为boss
现在要得到:
2 1 3 就是把关系摆出来.可以用存储过程.
大家帮忙啦..
------解决方案----------------------你的语句错误多多.
create table employee
(eid int,ename varchar(50))
go
create table relation
(eid int,bid int)
go
insert into employee
select 1, 'a ' union all
select 2, 'a ' union all
select 3, 'a '
go
insert into relation
select 2,1 union
select 1,3
go
select a.*,b.bid from relation a, relation b where a.bid = b.eid
drop table employee,relation
/*
eid bid bid
----------- ----------- -----------
2 1 3
(所影响的行数为 1 行)
*/