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
Break Down Revenue and Cost Variance
00:00
5 left

Break Down Revenue and Cost Variance

HardSQL · PostgreSQL

Problem

You are given monthly sales and cost data for product lines. Write a PostgreSQL query that breaks the month-over-month change in revenue and cost into key components: price effect, volume effect, and mix effect for each product line. Return the current month, prior month, product line, and the component values needed to explain the change.

Use the provided tables and keep the result at the product-line level. The query should compare each month to the immediately previous month for the same product line.

Schema

product_lines
ColumnTypeDescription
product_line_idPKINTPrimary key for the product line
product_line_nameVARCHAR(100)Readable product line name
monthly_financials
ColumnTypeDescription
financial_idPKINTPrimary key for the monthly financial record
product_line_idINTReferences product_lines.product_line_id
month_startDATEFirst day of the month
units_soldINTUnits sold during the month
revenueDECIMAL(12,2)Monthly revenue amount
costDECIMAL(12,2)Monthly cost amount
Tablesproduct_linesmonthly_financials
Interviewer

Your question is Break Down Revenue and Cost Variance. Start with the requirements and the two 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.