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
Compare Sales Before Product Launch
00:00
5 left

Compare Sales Before Product Launch

MediumSQL · PostgreSQL

Problem

NovaCart launched a new product on a known launch date and wants to compare product performance immediately before and after launch. Write a SQL query to measure pre-launch vs post-launch performance for each launched product.

Requirements

  1. For each launched product, compare the 30 days before launch with the 30 days after launch.
  2. Return these columns: product_id, product_name, launch_date, pre_orders, post_orders, pre_revenue, post_revenue, revenue_change_pct.
  3. Only include products where launch_date is not null.
  4. Sort by revenue_change_pct descending, then product_id ascending.

Schema

products
ColumnTypeDescription
product_idPKINTPrimary key for the product
product_nameVARCHAR(100)Name of the product
categoryVARCHAR(50)Product category
launch_dateDATEOfficial product launch date
orders
ColumnTypeDescription
order_idPKINTPrimary key for the order
customer_idINTCustomer placing the order
order_dateDATEDate when the order was placed
statusVARCHAR(20)Order status such as completed, canceled, or pending
order_items
ColumnTypeDescription
order_item_idPKINTPrimary key for the order line
order_idINTReferences orders.order_id
product_idINTReferences products.product_id
quantityINTNumber of units purchased
unit_priceDECIMAL(10,2)Unit selling price at time of purchase
Tablesproductsordersorder_items
Interviewer

Your question is Compare Sales Before Product Launch. 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.