LeetCode(数据库)- 页面推荐
Posted 程序员牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- 页面推荐相关的知识,希望对你有一定的参考价值。
题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1)
WITH t1 AS(SELECT user2_id user_id FROM Friendship WHERE user1_id = 1
UNION
SELECT user1_id FROM Friendship WHERE user2_id = 1)
SELECT DISTINCT page_id recommended_page FROM Likes li JOIN t1 ON li.user_id = t1.user_id
WHERE page_id NOT IN (SELECT page_id FROM Likes WHERE user_id = 1)
-- 解决方案(2)
SELECT DISTINCT page_id AS recommended_page
FROM Likes
WHERE user_id IN (
SELECT user1_id AS user_id FROM Friendship WHERE user2_id = 1
UNION ALL
SELECT user2_id AS user_id FROM Friendship WHERE user1_id = 1
) AND page_id NOT IN (
SELECT page_id FROM Likes WHERE user_id = 1
)
以上是关于LeetCode(数据库)- 页面推荐的主要内容,如果未能解决你的问题,请参考以下文章