Rank Employees by Salary per Department

Rank employees by salary within each department.

sql

SELECT name, department, salary, RANK() OVER (PARTITION BY department 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, partitioned by their respective department.

PromptDB can make mistakes. Please double-check responses.