← All SQL interview questions

Orders above the customer's own average

MediumSubqueriesAmazonFlipkart

A fraud analyst wants to spot orders that are unusually large for that particular customer, not compared with the whole platform.

From customer_orders, return order_id, customer_id, order_amount and customer_avg (that customer's average order amount, rounded to 2 decimals) for every order strictly above the customer's own average. Order by customer_id, then order_id.

Sample data

Table: customer_orders

14 row(s) · showing first 8

order_idINTcustomer_idINTorder_dateDATEorder_amountNUMERIC(10,2)
11012026-09-021200.00
21012026-09-153400.00
31012026-10-01800.00
41022026-09-055000.00
51022026-09-204500.00
61022026-10-109500.00
71032026-09-08700.00
81032026-09-25650.00