日期:2014-05-19  浏览次数:20334 次

同时转换二个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