Use RANK() and ROW_NUMBER() window functions to create leaderboards
I need a ranked leaderboard of all active sales reps by total revenue. Show their name, total revenue, rank (with ties getting the same rank), and a unique row number. The top performer should be rank 1. I want to see where the gaps are between tied reps.
Each hint you reveal reduces the XP you can earn. Try the query first.
Use RANK() OVER (ORDER BY total_rev DESC) for rank with ties and ROW_NUMBER() OVER (ORDER BY total_rev DESC) for unique numbering
You need to aggregate revenue first, then apply window functions — use a subquery to get per-rep totals, then SELECT with window functions on top
Filter to active Sales department employees in the inner query