关于INNER JOIN的简单问题
我有一个用户表:
Accounts_Users包括:
UserID(int), UserName(varchar)
1 张三
2 李四
还有一个交易表
AccountActivity 包括:
FromUserID ToUserID Amount
1 2 300.00
因为显示在网站上,当然要用UserName, 不能用UserID,如果我用查询语句:
SELECT FromUserID, ToUserID, Amount FROM AccountActivity 当然没有问题,但是如果我要求是用户名UserName, 请问怎么办 ?显然不能用
SELECT UserName, UserName, Amount FROM AccountActivity
INNER JOIN Accounts_Users
ON AccountActivity.UserID = Accounts_Users.UserID
[解决办法]
该回复于2013-05-31 13:03:06被管理员删除
[解决办法]
SELECT a.UserName as FromUsername, b.UserName as ToUsername, Amount FROM AccountActivity
INNER JOIN Accounts_Users a
ON AccountActivity.FromUserID = a.UserID
inner join Accounts_Users b
ON AccountActivity.ToUserID = b.UserID