Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 30-Day Sales Volume
00:00
5 left

Rolling 30-Day Sales Volume

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate the rolling 30-day sales volume for each product in our inventory.

Use the inventory products and sales records. Calculate sales by product and sales date, then determine the volume for the current date and the preceding 29 calendar days. Include only sales associated with products in the inventory.

Output

  1. One row per product and sales date.
  2. Columns: product_id, product_name, sales_date, daily_sales_volume, and rolling_30_day_sales_volume.
  3. Sort by product_id, then sales_date ascending.

Schema

products
ColumnTypeDescription
product_idPKINTUnique inventory product identifier
product_nameVARCHAR(100)Product name
skuVARCHAR(40)Stock keeping unit
categoryVARCHAR(60)Product category
sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier
product_idINTReferenced inventory product identifier
sale_dateDATECalendar date of the sale
quantityINTUnits sold in the record
Tablesproductssales
Interviewer

Your question is Rolling 30-Day Sales Volume. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.