Assign Row Numbers to Employees Table
Assign a row number to employees ordered by salary within each department.
sql
SELECT id, name, department_id, salary, ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS row_num FROM employees;
This query uses the ROW_NUMBER() window function to assign a unique sequential integer to each employee within their respective department_id partition, ordered by salary in descending order.
PromptDB can make mistakes. Please double-check responses.