All tasks

Ranking reviews with context

Advanced

Amazon level task. **Condition:** For each product, show the top-3 reviews by rating, as well as the next review after each top-3 (for comparison). **Table:** reviews (product_id, customer_id, rating, comment, created_at, ...) **Requirements:** 1. Rank reviews within each product by rating DESC, created_at DESC 2. For each of the top-3, show the data of the next review 3. Output product_id, rank, rating, comment, next_rating, next_comment **Hint:** Combination of RANK() and LEAD().

Category
Window Functions
Estimated time
~25 min
Databases
PostgreSQLGreenplum
Tags
FAANGInterviewRANKLEADContextоконные функции

Sign in to solve

Start Solving