Leetcode Problem 1892. Page Recommendations II

1892. Page Recommendations II

Leetcode Solutions

Page Recommendation Using Joins and Aggregation

  1. Use UNION to create a symmetric friendship table that includes both (user1_id, user2_id) and (user2_id, user1_id) pairs.
  2. Perform a LEFT JOIN between the symmetric friendship table and the Likes table to find all pages liked by friends of each user.
  3. Use another LEFT JOIN to exclude pages that the user has already liked.
  4. Group the results by user_id and page_id.
  5. Count the number of distinct friends who like each page.
  6. Select the user_id, page_id, and the count as friends_likes for the final output.
erDiagram
    Friendship {
        int user1_id
        int user2_id
    }
    Likes {
        int user_id
        int page_id
    }
    Friendship ||--o{ Likes : likes

Page Recommendation Using NOT EXISTS and Aggregation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...