当前位置: 代码迷 >> Sql Server >> 同时转换二个ID时如何写?请大家帮忙
  详细解决方案

同时转换二个ID时如何写?请大家帮忙

热度:94   发布时间:2016-04-27 21:06:59.0
同时转换二个ID时怎么写?请大家帮忙
表msgbox
sendtime,sendid,inceptid,msgbody
表users
userid   username
有一个查询
select   sendtime,sendid,inceptid,msgbody   from   msgbox
查询出来的sendid,inceptid为用户ID,想同时把sendid,inceptid转换为用户姓名,语句要怎么写啊?   sendid,inceptid   都对应表users   中的userid,
要是只转换一个我会写,同时转换二个就不会了,请大家帮忙!

------解决方案--------------------
Select
A.sendtime,
B.username As sendid,
C.username As inceptid,
A.msgbody
From
msgbox A
Left Join
users B
On A.sendid = B.userid
Left Join
users C
On A.inceptid = C.userid

------解决方案--------------------


select a.sendtime,(select username from users where userid = a.sendid),(select username from users where userid = a.inceptid),a.msgbody
from msgbox a
  相关解决方案