1892. Page Recommendations II

https://leetcode.com/problems/page-recommendations-ii

Description

Table: Friendship


+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| user1\_id      | int     |
| user2\_id      | int     |
+---------------+---------+
(user1\_id, user2\_id) is the primary key for this table.
Each row of this table indicates that the users user1\_id and user2\_id are friends.

Table: Likes


+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| user\_id     | int     |
| page\_id     | int     |
+-------------+---------+
(user\_id, page\_id) is the primary key for this table.
Each row of this table indicates that user\_id likes page\_id.

You are implementing a page recommendation system for a social media website. Your system will recommended a page to user_id if the page is liked by at least one friend of user_id and is not liked by user_id.

Write an SQL query to find all the possible page recommendations for every user. Each recommendation should appear as a row in the result table with these columns:

  • user_id: The ID of the user that your system is making the recommendation to.

  • page_id: The ID of the page that will be recommended to user_id.

  • friends_likes: The number of the friends of user_id that like page_id.

Return result table in any order.

The query result format is in the following example:

ac

Last updated

Was this helpful?