sales_regions (region) lists the sales regions; rep_sales (sale_id, region, rep_id, amount, closed_at) holds closed deals. A negative amount is a refund and counts against the rep.
Build the leaderboard: in each region, the top 3 reps by total amount (refunds included).
- •When two reps have the same total, the one who reached it first ranks higher: the rep whose last sale (refunds included) closed earlier. If that is also tied, the smaller
rep_id ranks higher. - •Every region gets exactly three rows, for places 1, 2 and 3. A place with no rep to fill it shows
rep_id and total as NULL — including every place in a region with no sales at all.
Columns: region, place, rep_id, total. Sort by region, then place.