56. Products Priced Above Their Category Average
MediumSubqueriescorrelated subquerysubquery in WHEREAVG
A correlated subquery in WHERE lets each outer row be tested against a value computed from rows related to it — here, the average price within the same category.
Task: return the products whose price is strictly greater than the average price of all products in the same category.
Return columns name, category, price. Order by category ascending, then name ascending.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.