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
Compute Category Sales by Location
00:00
5 left

Compute Category Sales by Location

MediumSQL · PostgreSQL

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
Interviewer

Your question is Compute Category Sales by 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.