Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
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.
Result columns · in this order
order_id | Order identifier; unique in this table. |
total_amount | Order total in dollars. |
How to approach it
Compare total_amount to twice the overall average computed in a scalar subquery.
Sample input
| order_id | total_amount |
|---|---|
| 1001 | 80 |
| 1004 | 220 |
| 1005 | 540 |
| 1010 | 640 |
| 1003 | 40 |
5 rows — all rows shown.
Expected output
| order_id | total_amount |
|---|---|
| 1010 | 640 |
| 1005 | 540 |
2 rows — all rows shown.
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.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.