题目链接:点击打开链接
题目大意:题目当中测试用例描述是有问题的,这个注意下,但是不影响最终判断,判断里的数据是正确的。
解题思路:奇怪为啥我注释的这条代码 NOT IN 数据 (2, 3) 的情况被过滤掉,不科学,函望大佬指点下,目前只能怀疑题目语法解析问题。
AC 代码
WITH t AS(SELECT * FROM Listens GROUP BY 1, 2, 3), tt AS(SELECT user1_id, user2_id FROM Friendship UNION ALL SELECT user2_id, user1_id FROM Friendship) SELECT DISTINCT l1.user_id, l2.user_id recommended_id FROM t l1 JOIN t l2 ON l1.user_id <> l2.user_id AND l1.day = l2.day AND l1.song_id = l2.song_id WHERE NOT EXISTS(SELECT 1 FROM tt WHERE l1.user_id = user1_id AND l2.user_id = user2_id) # WHERE (l1.user_id, l2.user_id) NOT IN (SELECT * FROM tt) -- 为啥不行? GROUP BY 1, 2, l1.day HAVING COUNT(DISTINCT l1.song_id) >= 3