Top Two Orders in Each Country

medium
Unit 12 · Window Functions V0/3 to milestone

For each country, return its two largest orders: country, id (order id) and total. Break ties by the lower order id. Countries with only one order return just that order. Sort by country, then total descending, then id.

Schema

customers(id, name, country, signup_date)
orders(id, customer_id, order_date, total)
#window-functions#top-n1 visible + 1 hidden tests
query.sql · SQLite
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Top Two Orders in Each Country · TechGradify