SQL Quest › SQL Interview Questions › Window Functions
Reviewed Twice, Scored Higher the Second Time
The product team wants to know who changed their mind upwards. In reviews, find every customer who reviewed the same product exactly twice, where the second review (by review_date) gave more stars than the first.
Show exactly these 2 columns: name (from customers) and product. Order by name, then product.
Two things decide the answer: a customer who reviewed a product three times does not count, even if their second score went up; and "second" means second by date, not by review_id — one customer's rows were entered out of order. An equal score is not higher.
Solve it in the browser editor →
Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect". Free accounts get 10 free challenge solves, and this can be one of them.
Schema
reviews
| review_id | customer_id | product | stars | review_date |
|---|---|---|---|---|
| 1 | 1 | Laptop Pro | 3 | 2024-02-01 |
| 2 | 2 | Wireless Mouse | 4 | 2024-02-03 |
| 3 | 7 | Office Chair | 4 | 2024-02-28 |
customers
| customer_id | name | signup_date | membership | total_orders | |
|---|---|---|---|---|---|
| 1 | John Smith | john.smith@email.com | 2023-01-15 | Gold | 15 |
| 2 | Emma Wilson | emma.wilson@email.com | 2023-03-20 | Silver | 8 |
| 3 | Michael Brown | michael.brown@email.com | 2023-02-10 | Gold | 12 |
Expected output: 3 rows — one Office Chair, two Laptop Pro
Hint
Concepts
SELECT Window Functions ROW_NUMBER PARTITION BY CTE Self-Join JOIN
Practise the topic: SQL practice questions · Window function practice · CTE practice · JOIN practice · Ranking function practice
Read the concept: SQL running total
In these company practice sets
A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.
Related questions
Where would this cost you points in an interview?
Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.
Take the readiness test