Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
Correlated subquery. A correlated subquery uses a column of the outer row, so it's worked out again for each row with that row's value. Use it to compare a row with its own group: a product with its category, an order line with that product's other lines. Give the inner table its own alias so the two copies don't get mixed up.
select oi.order_id, oi.product_id, oi.quantity from order_items oi where oi.quantity > ( select 2.5 * avg(x.quantity) from order_items x where x.product_id = oi.product_id )
Priya Raman wants to know which products carry their category: those whose completed revenue is above the average for products in the same category.
Return product_name, category and revenue (completed revenue, 2 decimals) for every product whose revenue is above the average revenue of the products in its own category.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe