1

表 - 朋友

    friend_id     | friend_one    | friend_two   | role 
+--------------------------------------------------------------------------------------------+
|1:    44               34              34          me
|2:    45               35              35          me
|3:    46               35              34          fri
+--------------------------------------------------------------------------------------------+

我需要计算,谁在关注,谁是关注者.. 差不多了,我在下面得到了一些答案,但大多只是给我静态数字,但到目前为止感谢您的帮助,它给了我一个开始的地方。FRIEND_ONE = 34(在表用户 34 = 他们的 uid 与 35 相同,依此类推)


我以前得到过这个答案,但它只是不断地为这两个中的一个返回 0 或 3。

select friend_one, count(*) as count
from friends
where friend_one != friend_two 
group by friend_one;

if you want the count for a specific user, do this:

select count(*) as count
from friends
where friend_one != friend_two 
and friend_one = $uid
4

0 回答 0