首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-02-23 
同时转换二个ID时怎么写?请大家帮忙表msgboxsendtime,sendid,inceptid,msgbody表usersuseridusername有一

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

热点排行