Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Joining Tables With Sales Filters

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Joining Tables With Sales Filters. Start with the requirements and the three tables on the right.

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.

Problem

HARMAN's Business Analytics team wants a quarterly view of qualifying North American sales across JBL, Harman Kardon, and related product lines. Write a PostgreSQL query that joins orders, order items, and products to identify products meeting the specified sales criteria.

Requirements

  1. Include only orders from North America with status Completed between 2025-01-01 and 2025-03-31.
  2. Include only products in the Audio category.
  3. Calculate total units, distinct order count, and net revenue after discounts, treating a missing discount as 0%.
  4. Keep products with net revenue of at least 250, label each result using CASE, and sort by net revenue descending.

Schema

sales_orders
ColumnTypeDescription
order_idPKINTUnique sales order identifier
order_dateDATEDate the order was placed
regionVARCHAR(50)Geographic sales region
statusVARCHAR(20)Order processing status
order_items
ColumnTypeDescription
item_idPKINTUnique order item identifier
order_idINTReferences sales_orders.order_id
product_idINTReferences products.product_id
quantityINTNumber of units sold
unit_priceNUMERIC(10,2)Price per unit before discount
discount_percentNUMERIC(5,2)Discount percentage applied to the item
products
ColumnTypeDescription
product_idPKINTUnique HARMAN product identifier
product_nameVARCHAR(150)HARMAN product name
categoryVARCHAR(50)Product category
Tablessales_ordersorder_itemsproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results