SQL Series #3: ROW_NUMBER() Window Function
Problem Statement: Imagine you work for a retail company, and you want to analyze the performance of your salespeople. You have a table sales that records each sale made by your sales team, including the salesperson's ID, the sale date, and the sale amount.
You need to generate a report that ranks each sale for every salesperson based on the sale amount. This can help you identify top-performing salespeople for each period or determine who made the most significant sales in a given timeframe.
Input
Solution
ROW_NUMBER() OVER (...):
PARTITION BY salesperson_id:
ORDER BY amount DESC:
Output