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
Optimize Warehouse SQL Performance
00:00
5 left

Optimize Warehouse SQL Performance

MediumSQL · PostgreSQL

Problem

How do you optimize SQL queries for performance in a warehouse environment?

Treat this as a hands-on SQL exercise. Using the provided warehouse tables, write an efficient query that preserves correctness while calculating monthly revenue metrics and comparisons.

Output

  1. One row per month, region, and product category.
  2. Columns: month_start, region, category, revenue, order_count, prior_month_revenue, revenue_change_pct, and monthly_revenue_rank.
  3. Include completed sales from January through March 2025, order by month_start, revenue descending, region, and category.

Schema

fact_sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
sale_dateDATEDate of the sale
customer_idINTPurchasing customer
product_idINTPurchased product
quantityINTUnits purchased
net_amountDECIMAL(12,2)Net sale amount
statusVARCHAR(20)Sale processing status
dim_customer
ColumnTypeDescription
customer_idPKINTCustomer identifier
regionVARCHAR(30)Customer sales region
segmentVARCHAR(30)Customer segment
dim_product
ColumnTypeDescription
product_idPKINTProduct identifier
product_nameVARCHAR(80)Product name
categoryVARCHAR(30)Product category
dim_date
ColumnTypeDescription
date_keyPKDATECalendar date
month_startDATEFirst day of the calendar month
is_business_dayBOOLEANWhether the date is a business day
Tablesfact_salesdim_customerdim_productdim_date
Interviewer

Your question is Optimize Warehouse SQL Performance. Start with the requirements and the four 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.