题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1) select distinct a.user1_id, a.user2_id from Friendship a, Listens b, Listens c where a.user1_id = b.user_id AND a.user2_id = c.user_id AND b.song_id = c.song_id AND b.day = c.day group by a.user1_id, a.user2_id, b.day having COUNT(distinct b.song_id) >= 3 -- 解决方案(2) WITH t AS(SELECT * FROM Listens GROUP BY 1, 2, 3) SELECT DISTINCT l1.user_id user1_id, l2.user_id user2_id FROM t l1 JOIN t l2 ON l1.user_id < l2.user_id AND l1.day = l2.day WHERE (l1.user_id, l2.user_id) IN (SELECT * FROM Friendship) GROUP BY 1, 2, l1.day HAVING COUNT(IF(l1.song_id = l2.song_id, 1, NULL)) >= 3