0

我有两张桌子

帐户 { acc_id,分数,... }

朋友 { acc_id,friend_id }

我需要查询来选择约翰的所有朋友的分数(例如)

就像是

SELECT (acc_id,score) FROM accounts WHERE (表友包含条目 (John,acc_id))

是否可以编写这样的查询?

谢谢

4

2 回答 2

0

Yes, you will need to use a subquery. It should look something like this:

    Select acc_id, score from accounts 
    where acc_id in (select acc_id where friend_id = 'John'sID');
于 2013-07-23T16:23:48.623 回答
0

使用子查询:

Select acc_id, score from accounts 
where acc_id in (select acc_id from friends where friend_id = 'John'sID');

或使用加入:

Select accounts.acc_id, score from accounts 
Left Join friends  using (acc_id)
where  friend_id = 'John'sID';
于 2013-07-26T11:42:58.137 回答