Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compute Category Sales by Location

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

Your question is Compute Category Sales by Location. Start with the requirements and the three 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

Given sales, item category, and pricing tables, write a SQL query to calculate the total sales value for each item category and location during a specified period.

Use the period from January 1, 2024 through January 31, 2024, with the start date included and the end date excluded. Calculate sales value as quantity multiplied by the unit price valid on the sale date. Exclude sales without an item category or location.

Output

  1. One row per item category and location, with columns item_category, location, and total_sales_value.
  2. Sort by item_category ascending, then location ascending.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
item_idINTSold item identifier
locationVARCHAR(50)Sale location
sale_dateDATEDate of sale
quantityINTNumber of units sold
item_categories
ColumnTypeDescription
item_idPKINTUnique item identifier
category_nameVARCHAR(100)Item category name
pricing
ColumnTypeDescription
price_idPKINTUnique pricing record identifier
item_idINTPriced item identifier
unit_priceNUMERIC(12,2)Unit selling price
effective_fromDATEInclusive start date for the price
effective_toDATEExclusive end date for the price
Tablessalesitem_categoriespricing
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results