Complete the code to assign a unique row number to each employee ordered by salary.
SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY [1]) AS row_num FROM employees;The ROW_NUMBER() function assigns a unique number to each row based on the order of the salary column.
Complete the code to reset the row number for each department.
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY salary) AS dept_rank FROM employees;The PARTITION BY clause groups rows by department, so row numbers restart for each department.
Fix the error in the code to correctly assign row numbers partitioned by department and ordered by hire_date.
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY [2]) AS rn FROM employees;
The PARTITION BY should be department to reset numbering per department, and ORDER BY should be hire_date to order employees by their hire date.
Fill both blanks to assign row numbers partitioned by department and ordered by salary descending.
SELECT employee_id, department, salary, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY salary [2]) AS rank FROM employees;
Partitioning by department groups employees, and ordering by salary DESC ranks highest salary first.
Fill all three blanks to select employee name, assign row numbers partitioned by department, ordered by hire_date ascending.
SELECT [1], ROW_NUMBER() OVER (PARTITION BY [2] ORDER BY [3]) AS row_num FROM employees;
Select employee_name, partition by department to group employees, and order by hire_date ascending to number employees by hire date.