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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Year-over-Year Product Growth
00:00
5 left

Year-over-Year Product Growth

MediumSQL · PostgreSQL

Problem

Stryker's commercial analytics team wants to monitor annual sales performance for the Mako product line. Write a PostgreSQL query that calculates year-over-year sales growth from the available sales records.

Requirements

  1. Join sales to products and include only products where product_line = 'Mako'.
  2. Aggregate total sales by calendar year using sale_date and sales_amount.
  3. Compare each year with the immediately preceding year and calculate growth as a percentage.
  4. Return the years in ascending order. Return NULL for the first year when no prior-year sales exist.

Output details

  • Return columns in this order: sales_year, total_sales, prior_year_sales, and yoy_growth_pct.
  • Round yoy_growth_pct to two decimal places.
  • Return NULL for yoy_growth_pct when prior_year_sales is zero.

Schema

products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(100)Name of the Stryker product
product_lineVARCHAR(50)Stryker product line associated with the product
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
product_idINTEGERProduct associated with the sale
sale_dateDATEDate on which the sale was recorded
sales_amountNUMERIC(12,2)Sales value for the transaction
Tablesproductssales
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.