AnalystPath

Weighted Average Rating

SQLEasyJunior level~15 min

Problem

Table: `rating_bucket`

| Column Name | Type |
|---|---|
| bucket_id | int |
| stars | int |
| respondents | int |

`bucket_id` is the primary key. Instead of one row per survey response, the data is compressed: each row says that `respondents` people gave the same `stars` rating.

Compute the average rating across all individual respondents, rounded to 2 decimal places, and alias it `avg_rating`.

Tables

Example rows — the live problem includes the full dataset.

rating_bucket
bucket_idstarsrespondents
1510
246
333

Expected output

Your answer should return 1 row with the columns avg_rating.

Starter code (SQL)

SELECT *
FROM rating_bucket;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions