Complete the code to assign a row number to each employee ordered by their 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 ordered by 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 DESC) AS dept_rank FROM employees;ORDER BY column in PARTITION BY instead of grouping column.PARTITION BY when needed.The PARTITION BY department clause restarts the row numbering 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 department ORDER BY [1]) AS hire_rank FROM employees;PARTITION BY incorrectly.The row numbers should be ordered by hire_date to rank employees by their hiring date within each department.
Fill both blanks to assign row numbers partitioned by department and ordered by salary ascending.
SELECT employee_id, department, salary, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY [2] ASC) AS salary_rank FROM employees;
Partitioning by department groups employees, and ordering by salary ascending ranks them by salary within each department.
Fill all three blanks to assign row numbers partitioned by department, ordered by salary descending, and select employee name.
SELECT [1], department, salary, ROW_NUMBER() OVER (PARTITION BY [2] ORDER BY [3] DESC) AS rank FROM employees;
Select employee_name, partition by department, and order by salary descending to rank employees by salary within each department.