Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Total Sales by Category and Location
00:00
5 left

Total Sales by Category and Location

MediumSQL · PostgreSQL

Problem

Amazon Kuiper Commercial Services needs a sales summary for a reporting period. Write a PostgreSQL query that calculates the total sales value by item category and location from 2025-01-01 through 2025-01-31, inclusive.

Requirements

  1. Join sales to item categories and effective-dated pricing.
  2. Include only sales in the specified period and apply the price active on each sale date.
  3. Aggregate quantity * unit_price by category and location, treating a NULL quantity as zero.
  4. Exclude sales without a matching category or valid price, and order by location with NULL locations first, then category name.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
item_idINTSold item identifier
sale_dateDATEDate on which the sale occurred
locationVARCHAR(100)Commercial service location
quantityINTNumber of units sold
item_categories
ColumnTypeDescription
item_idPKINTUnique item identifier
category_nameVARCHAR(100)Item category name
pricing
ColumnTypeDescription
item_idINTItem associated with the price
effective_fromDATEInclusive price start date
effective_toDATEExclusive price end date, NULL indicates an active price
unit_priceNUMERIC(10,2)Price per unit
Tablessalesitem_categoriespricing
Interviewer

Your question is Total Sales by Category and Location. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.