Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Star Rating by Month

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Average Star Rating by Month. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Amazon's Business Analytics team wants to monitor how customer sentiment changes for products over time. Write a PostgreSQL query that calculates the average published star rating for each product and calendar month.

Requirements

  1. Join products with customer_reviews using product_id.
  2. Include only published reviews with a non-null star rating.
  3. Group results by product and review month, displaying the month as YYYY-MM.
  4. Round the average rating to two decimal places and order results by product ID and month.

Schema

products
ColumnTypeDescription
product_idPKINTUnique Amazon product identifier
product_nameVARCHAR(150)Product display name
categoryVARCHAR(80)Product category
customer_reviews
ColumnTypeDescription
review_idPKINTUnique customer review identifier
product_idINTReferenced product identifier
star_ratingINTCustomer rating from 1 to 5
review_dateDATEDate the review was submitted
review_statusVARCHAR(20)Moderation status of the review
Tablesproductscustomer_reviews
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results