Rank Employees by Salary Using Rank

Find the employee salary rank across the entire company.

sql

SELECT id, name, salary, RANK() OVER (ORDER BY salary DESC) as salary_rank FROM employees;

This query uses the RANK() window function to assign a numerical rank to each employee based on their salary in descending order across the entire employees table.

PromptDB can make mistakes. Please double-check responses.