Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Average Star Rating by Month
00:00
5 left

Average Star Rating by Month

EasySQL · PostgreSQL

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
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.