Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Core SQL Query Writing

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

Your question is Core SQL Query Writing. 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

TE Connectivity analysts need a quarterly view of customers purchasing AMP connector products. Write a PostgreSQL query that identifies customers meeting both order-count and sales-value thresholds.

Requirements

  1. Join customers, orders, and order_items.
  2. Include only completed orders placed from January 1 through March 31, 2025, with product_family = 'AMP Connector'.
  3. Return each customer’s completed order count and total connector sales, calculated as quantity * unit_price.
  4. Use HAVING to keep customers with at least two qualifying orders and at least $1,000 in sales. Sort by sales descending, then customer name.

Schema

customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer name
regionVARCHAR(50)Sales region
orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTRelated customer identifier
order_dateDATEDate the order was placed
order_statusVARCHAR(20)Order lifecycle status
order_items
ColumnTypeDescription
order_item_idPKINTLine-item identifier
order_idINTRelated order identifier
product_familyVARCHAR(80)TE Connectivity product family
product_nameVARCHAR(120)Product description
quantityINTUnits ordered
unit_priceDECIMAL(10,2)Price per unit
Tablescustomersordersorder_items
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results