题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1) select a.user1_id,a.user2_id from (select a.user_id user1_id, b.user_id user2_id, rank() over(order by COUNT(1) desc) rn from Relations a, Relations b where a.user_id < b.user_id AND a.follower_id = b.follower_id group by a.user_id, b.user_id) A WHERE A.rn = 1 -- 解决方案(2) WITH t AS(SELECT r1.user_id user1_id, r2.user_id user2_id, COUNT(*) cnt FROM Relations r1 JOIN Relations r2 ON r1.user_id < r2.user_id AND r1.follower_id = r2.follower_id GROUP BY 1, 2 ORDER BY 3 DESC) SELECT user1_id, user2_id FROM t WHERE (SELECT MAX(cnt) FROM t) = cnt