SQL
Lab
Airbnb Airbnb Interview Question 04

Average Review
Score
per Listing

Find the average review score per listing.

Table Schema

Inspect
Table

interactive
ColumnType
review_idinteger
listing_idinteger
ratinginteger

Sample Data

Input
Output

Sample Input: reviews
review_idlisting_idrating
11015
21014
31023
41024
51035
61035
Expected Output
listing_idavg_rating
1014.50
1023.50
1035.00

SQL Editor

Run
Query

postgresql
Waiting for query

listing_idavg_rating
1014.50
1023.50
1035.00

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

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 listing_id, ROUND(AVG(rating), 2) AS avg_rating
FROM reviews
GROUP BY listing_id;

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving