Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Sales Metrics With Edge Cases

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

Your question is SQL Sales Metrics With Edge Cases. 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

Netflix wants a monthly sales view covering every retail store, including months in which a store had no sales. Write a PostgreSQL query for January through March 2025.

Requirements

  1. Return one row for every store and every month in the reporting period.
  2. Calculate transaction count, total sales, and average sale amount.
  3. Represent missing sales as zero for count, revenue, and average sale amount.
  4. Preserve stores with no matching sales and exclude sales outside the reporting period.

Schema

stores
ColumnTypeDescription
store_idPKINTUnique store identifier
store_nameVARCHAR(100)Name of the store
regionVARCHAR(50)Geographic region containing the store
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
store_idINTStore associated with the sale
sale_dateDATEDate on which the sale occurred
amountNUMERIC(10,2)Sale amount
sale_channelVARCHAR(30)Channel used for the sale
Tablesstoressales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results