1951. 查询具有最多共同关注者的所有两两结对组
写出一个查询语句,找到具有最多共同关注者的所有两两结对组。换句话说,如果有两个用户的共同关注者是最大的,我们应该返回所有具有此最大值的两两结对组
结果返回表,每一行应该包含user1_id和 user2_id,其中user1_id < user2_id.
返回结果 不要求顺序 。
查询结果格式如下例
select
user1_id,
user2_id
from
(select
user1_id,
user2_id,
rank() over(order by cn desc) as rk
from
(select
r1.user_id as user1_id,
r2.user_id as user2_id,
count(*) as cn
from
Relations as r1 join Relations as r2 on r1.follower_id=r2.follower_id and r1.user_id<r2.user_id
GROUP BY
1,2) as t1) as t2
where
rk=1