Orders by status

aggregations

Orders by status

Target SQL Interview Question

Target's operations team tracks how online orders end up: completed, canceled or refunded.

For each status, find the number of orders as order_count and the average order amount as avg_amount. Do not round the average.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • ML Engineer

ordersTable35 rows

Column NameType
order_idBIGINT
customer_idBIGINT
order_dateDATE
statusVARCHAR
amountDOUBLE

ordersExample Input

order_idcustomer_idorder_datestatusamount
100112024-01-05completed120.5
100222024-01-07completed2400
100312024-01-11completed89.99
100432024-01-15canceled45
100542024-01-18completed610.75
100622024-01-22completed1850.25
100752024-01-29completed3200
100812024-02-02refunded75
100962024-02-06completed55.4
101032024-02-09completed132.6

Example Output

statusorder_countavg_amount
canceled145
completed81057.4362
refunded175

Explanation

Eight of the ten orders in the example were completed, and they average about 1,057.44. There is one canceled order worth 45 and one refunded order worth 75, so each of those averages equals that single amount.

The example above is a small slice of the data. Your query runs against the full tables.