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
SQL for Retail Availability Metrics
00:00
5 left

SQL for Retail Availability Metrics

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze retail performance by joining sales, inventory, and promotion tables, and calculate availability, sell-through, and promotion lift by region.

Use the supplied tables and data. Treat missing sales as zero, and include inventory records even when no sale or promotion matches.

Output

  1. One row per region with region, availability_pct, sell_through_pct, promotion_lift_pct, and promotion_lift_rank.
  2. Availability is the percentage of inventory records with positive ending stock. Sell-through is sold units divided by sold units plus ending stock. Promotion lift compares average units sold on promotion with average units sold without promotion.
  3. Round percentage metrics to two decimal places. Order by promotion_lift_rank, then region.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier
sale_dateDATEDate on which units were sold
regionVARCHAR(40)Retail region
product_codeVARCHAR(30)Product identifier
units_soldINTUnits sold in the record
inventory
ColumnTypeDescription
inventory_idPKINTUnique inventory observation identifier
inventory_dateDATEDate of the inventory observation
regionVARCHAR(40)Retail region
product_codeVARCHAR(30)Product identifier
ending_stockINTUnits remaining at the end of the day
promotions
ColumnTypeDescription
promotion_idPKINTUnique promotion identifier
regionVARCHAR(40)Region where the promotion applies
product_codeVARCHAR(30)Product identifier
promotion_nameVARCHAR(80)Promotion label
promotion_startDATEPromotion start date
promotion_endDATEPromotion end date
Tablessalesinventorypromotions
Interviewer

Your question is SQL for Retail Availability Metrics. 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.