Digits
n Data
Netflix SQL Interview Question 07

Top
Rated
Content

Find the content with the highest average rating.

Schema

Table
Setup

Column NameTypeDescription
content_idintegerReviewed content identifier.
ratingintegerRating value.

Sample Data

Input
Output

Sample Input: reviews
content_idrating
14
15
13
23
24
32
33
45
44
Expected Output
content_idavg_rating
44.5

SQL Editor

Run
Query

postgresql
Waiting for query

content_idavg_rating
44.5

Hints

Unlock
Clues

Hint 01: Average ratings at the content level.
Hint 02: Use AVG(rating).
Hint 03: Order by avg_rating descending and keep one row.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  content_id,
  AVG(rating) AS avg_rating
FROM reviews
GROUP BY content_id
ORDER BY avg_rating DESC
LIMIT 1;

Explanation

Step By
Step

01

Group review rows by content_id.

02

Calculate average rating for each content_id.

03

Return the highest-rated content.

Related Questions

Keep
Solving