Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.