CODE WORKSPACE

Flag outlier orders

Return order_id and total_amount for orders whose total_amount is more than twice the average order value. Order by total_amount DESC, then order_id ASC.

Compare total_amount to twice the overall average computed in a scalar subquery.

Sample input

ordersAcross all 12 orders the average total is 180, so the threshold is 2 × 180 = 360.
order_idtotal_amount
100180
1004220
1005540
1010640
100340

Expected output

Expected outputOrders above twice the average value, highest first — flagged for review.
order_idtotal_amount
1010640
1005540

Constraints

Use a scalar subquery, 2 * (SELECT AVG(total_amount) FROM orders), as the threshold. Keep only orders above it. Flag, do not delete.

Expected skills

Statistical outlier detection with a scalar-subquery threshold.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.