All SQL problems
HardWindow
Top-selling product per city
For each city, return the product that has the highest total delivered revenue. Use a window function (ROW_NUMBER) so ties break deterministically.
- #window
- #row-number
- #top-n-per-group
Schema (SQLite, in-browser)
customers (id, name, city, signup_date) products (id, name, category, price) orders (id, customer_id, order_date, status) order_items (order_id, product_id, quantity)
Sample input
4 cities
Expected shape
4 rows
sql-top-per-group.sqlSQLite
Result
Press “Run query” to execute against the sample database.
