2,668
社区成员
发帖
与我相关
我的任务
分享
select a.id,
nvl((select name from t_user where id=a.userid1),'未指定') username1,
nvl((select name from t_user where id=a.userid2),'未指定') username2
from A a;
if object_id('a') is not null drop table a
create table a (id varchar (5),uid1 varchar (5),uid2 varchar (5) )
insert into a (id,uid1,uid2)
select 0,0,NULL union all
select 1,NULL,1 union all
select 2,2,1
if object_id('usr') is not null drop table usr
create table usr (id varchar (5),nm varchar (5) )
insert into usr (id,nm)
select 0,'zh' union all
select 1,'li' union all
select 2,'w'
select a.id,
(case when uid1=usr.id then usr.nm else NULL end )as nm1 ,
(case when uid2=usr.id then usr.nm else NULL end )as nm2
from a join usr on a.id=usr.id
select t1.id,
nvl((select t2.name from user t2 where t1.userid1=t2.id),'未指定') username1,
nvl((select t3.name from user t3 where t1.userid2=t3.id),'未指定') username2
from a t1