Orders above the average

subqueries

Orders above the average

Walmart SQL Interview Question

Walmart's finance team wants to review online orders that are bigger than a typical order.

List the order_id and amount of every order worth more than the average order. Use every order, whatever its status, to work out the average.

Asked of

  • Data Analyst
  • Business Analyst
  • Product Analyst
  • Data Scientist
  • 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

order_idamount
10022400
10061850.25
10073200

Explanation

The ten orders in the example average about 857.95. Only orders 1002, 1006 and 1007, worth 2,400, 1,850.25 and 3,200, are above that. Every other order is worth less than the average.

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