Rank event types per country
Return country, event name, event count and rank within country by count descending. Use DENSE_RANK and order by country then event name.
Try it yourself
Open a fresh temporary product analytics dataset. Write your query and use Check answer. Checking uses a separate, clean sample so edits to your workspace cannot change the expected answer. Matches are based on this dataset, not a proof for every possible database.
Open exercise →Sample schema
users(id, country, signed_up) events(id, user_id, event_name, occurred_at, properties)
About this dataset · Learning paths · SQL reference
Show a hint
Aggregate in a CTE, then apply DENSE_RANK partitioned by country.
Show one solution
WITH counts AS (SELECT u.country,e.event_name,COUNT(*) AS n FROM events e JOIN users u ON u.id=e.user_id GROUP BY u.country,e.event_name) SELECT country,event_name,n,DENSE_RANK() OVER (PARTITION BY country ORDER BY n DESC) FROM counts ORDER BY country,event_name;Other queries can produce the same answer. Column aliases are ignored; column order and row order are checked.