SQL practice: Top N Per Group
Chapter 26 · 12 questions · included in full access
Question 1 · easy
Solve it in your browserFind the single highest-paid employee in each branch.
Question 2 · easy
Solve it in your browserFind each customer's most recent order.
Question 3 · medium
Solve it in your browserFind the top 2 most expensive products in each category.
Question 4 · medium
Solve it in your browserSplit customers into 4 buckets by total spend and show bucket 1.
Question 5 · medium
Solve it in your browserFind the best-selling product in each branch, by total quantity.
Question 6 · medium
Solve it in your browserFind each branch's single highest-value order.
Question 7 · medium
Solve it in your browserFind the 2nd most expensive product in each category.
Question 8 · medium
Solve it in your browserFind each customer's first ever order.
Question 9 · medium
Solve it in your browserUse the duplicate-finding trick on order_items, partitioning by order_id and product_id. Are there any duplicates?
Question 10 · medium
Solve it in your browserFind the top 3 employees by revenue handled. Does this one need the pattern at all?
Question 11 · hard
Solve it in your browserFind the highest-paid employee in each role.
Question 12 · hard
Solve it in your browserRun Step 2 of the chapter's example but remove PARTITION BY p.category. What does rn = 1 give you now, and why?
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing