Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Weekly Sales Comparison

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

Your question is SQL Weekly Sales Comparison. 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

AT&T Operations Managers need a weekly view of sales performance across AT&T retail stores. Write a PostgreSQL query that aggregates net sales by store and calendar week, then compares each result with the same store's prior week.

Requirements

  1. Join sales to att_stores so the output includes the AT&T store name and region.
  2. Treat NULL sale amounts as zero and aggregate sales by store and Monday-based week.
  3. Include the prior week's sales, the dollar change, and percentage change. Return NULL for comparisons without a prior week or where the prior week's sales equal zero.
  4. Sort by store ID and week start date.

Schema

att_stores
ColumnTypeDescription
store_idPKINTUnique AT&T store identifier
store_nameVARCHAR(100)AT&T retail store name
regionVARCHAR(50)Operating region
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
store_idINTAT&T store associated with the sale
sale_dateDATEDate the sale was recorded
amountNUMERIC(10,2)Net sale amount, including returns
Tablesatt_storessales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results