Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Queries to Extract and Validate Data
00:00
5 left

SQL Queries to Extract and Validate Data

MediumSQL · PostgreSQL

Problem

How do you write queries to extract, join, and validate data at Best Buy?

Use the provided Best Buy order, order-item, and product data. Return completed orders and classify each order line according to whether its product reference, quantity, prices, and calculated total are valid.

Output

  1. One row per order item from completed orders.
  2. Columns: order_id, order_date, item_id, product_sku, product_name, quantity, recorded_unit_price, recorded_line_total, and validation_status.
  3. Include missing products and invalid lines, and order by order_id, then item_id.

Schema

best_buy_orders
ColumnTypeDescription
order_idPKINTUnique Best Buy order identifier
order_dateDATEDate the order was placed
statusVARCHAR(20)Order lifecycle status
best_buy_order_items
ColumnTypeDescription
item_idPKINTUnique order-item identifier
order_idINTOrder containing the item
product_skuVARCHAR(30)Referenced product SKU, when available
quantityINTQuantity purchased
unit_priceNUMERIC(10,2)Unit price recorded on the order
line_totalNUMERIC(10,2)Recorded extended price for the item
best_buy_products
ColumnTypeDescription
skuPKVARCHAR(30)Unique product stock-keeping unit
product_nameVARCHAR(100)Product display name
current_priceNUMERIC(10,2)Current catalog price
Tablesbest_buy_ordersbest_buy_order_itemsbest_buy_products
Interviewer

Your question is SQL Queries to Extract and Validate Data. 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.