LeetCode(数据库)- Leetcodify Friends Recommendations

简介: LeetCode(数据库)- Leetcodify Friends Recommendations

题目链接:点击打开链接


题目大意:题目当中测试用例描述是有问题的,这个注意下,但是不影响最终判断,判断里的数据是正确的。


解题思路:奇怪为啥我注释的这条代码 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


目录
相关文章
|
数据库
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
|
SQL 数据库
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
|
SQL 数据库
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
|
数据库
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
202 0
|
数据库
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
117 0
|
数据库
LeetCode(数据库)- Number of Accounts That Did Not Stream
LeetCode(数据库)- Number of Accounts That Did Not Stream
117 0
|
数据库
LeetCode(数据库)- The Airport With the Most Traffic
LeetCode(数据库)- The Airport With the Most Traffic
132 0
|
数据库
LeetCode(数据库)- The Category of Each Member in the Store
LeetCode(数据库)- The Category of Each Member in the Store
119 0
|
数据库
LeetCode(数据库)- 上级经理已离职的公司员工
LeetCode(数据库)- 上级经理已离职的公司员工
132 0
|
数据库
LeetCode(数据库)- First and Last Call On the Same Day
LeetCode(数据库)- First and Last Call On the Same Day
121 0