Average Review Ratings
Amazon 👶 Easy SQL
Beginner Mode

Objective

Write a SQL query to calculate the average star rating per product by month from a product reviews table.

Table Schema:

  • product_reviews
Column Type Description
review_id INTEGER Unique identifier for each review
product_id INTEGER ID of the product being reviewed
review_date DATETIME Date and time when the review was submitted
star_rating INTEGER Star rating given (1-5 scale)

Task Requirements:

  • Group reviews by month and product
  • Calculate the average star rating for each product in each month
  • Round the average rating to the nearest integer
  • Sort results by month and then by product ID

Output columns: review_month, product_id, avg_rating

Examples

Example 1:

Input:

product_reviews
product_idreview_datereview_idstar_rating
1012024-01-15 10:00:0015
1012024-01-20 11:00:0024
1022024-01-25 12:00:0033
1012024-02-10 13:00:0045
1022024-02-15 14:00:0054

Output:
avg_ratingproduct_idreview_month
51012024-01-01
31022024-01-01
51012024-02-01
41022024-02-01
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →