D8LooPFocus modeCODE WORKSPACE
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
| order_id | total_amount |
|---|---|
| 1001 | 80 |
| 1004 | 220 |
| 1005 | 540 |
| 1009 | 30 |
| 1010 | 640 |
Expected output
| order_id | total_amount |
|---|---|
| 1010 | 640 |
| 1005 | 540 |
| 1004 | 220 |
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.
Run the SQL query to inspect preview rows.