Followee Follower
A B
B C
B D
B E
A F
F G
F H
B H
如何在这种情况下查询“A”的2级关注者的数量是多少?
答案 0 :(得分:1)
我认为这很容易
select count(distinct t1.Follower)
from t
join
t t1
on t.Follower=t1.Followee
where t.Followee='A'
答案 1 :(得分:0)
让表的名称为“follow”。找到第二学位的粉丝是“A”:
select count(follower) from follows
where followee in
(select distinct follower from follows where followee='A')
如果你想找到所有被跟随者的第二学位追随者数量:
select f2.followee, count(f1.follower)
from follows f1 inner join follows f2
on f2.follower=f1.followee
group by f2.followee
答案 2 :(得分:0)
select a.followee,count(DISTINCT a.followee,b.follower) from following a
left join following b
on b.followee = a.follower
left join following d
on d.followee = a.followee and d.follower = b.follower
where d.followee is null
GROUP BY a.followee
答案 3 :(得分:0)
假设表的名称为tbl。
SELECT count (distinct tbl.follower)
FROM tbl
JOIN
(SELECT distinct follower FROM tbl WHERE followee = 'A') AS tbl2
ON tbl.followee = tbl2.follower
答案是5。