CODE WORKSPACE

Above average order amount

Return order_id and total_amount for orders whose total_amount is above the overall average order amount. Order by total_amount descending, then order_id ascending.

Compare total_amount to (SELECT AVG(total_amount) FROM orders).

Sample input

ordersThe overall AVG(total_amount) across all 12 orders is 180.
order_idtotal_amount
100180
1004220
1005540
100930
1010640

Expected output

Expected outputOnly orders above the 180 average, largest first.
order_idtotal_amount
1010640
1005540
1004220

Constraints

Use a scalar subquery (SELECT AVG(total_amount) FROM orders) in the WHERE clause. Order by total_amount DESC, order_id ASC.

Expected skills

Scalar subquery thresholds and deterministic ordering.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.