Understanding the Difference Between RANK and DENSE_RANK in SQL
📖 Scenario: You work in a sales department and want to rank salespeople based on their monthly sales. You want to see how RANK and DENSE_RANK functions assign ranks when there are ties in sales amounts.
🎯 Goal: Create a simple sales table and write SQL queries to apply RANK() and DENSE_RANK() window functions to understand their differences in ranking tied values.
📋 What You'll Learn
Create a table called
sales with columns salesperson and monthly_sales.Insert exactly these rows into
sales: ('Alice', 500), ('Bob', 700), ('Charlie', 700), ('David', 400).Write a query using
RANK() to rank salespeople by monthly_sales in descending order.Write a query using
DENSE_RANK() to rank salespeople by monthly_sales in descending order.💡 Why This Matters
🌍 Real World
Ranking salespeople or products based on performance metrics is common in business reports and dashboards.
💼 Career
Understanding ranking functions helps in writing SQL queries for data analysis, reporting, and decision-making in many data-related jobs.
Progress0 / 4 steps