0
0
SQLquery~10 mins

ROW_NUMBER function in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assign a unique row number to each employee ordered by salary.

SQL
SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY [1]) AS row_num FROM employees;
Drag options to blanks, or click blank then click option'
Aname
Bemployee_id
Cdepartment
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that does not exist in the table.
Forgetting to use ORDER BY inside the OVER clause.
2fill in blank
medium

Complete the code to reset the row number for each department.

SQL
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY salary) AS dept_rank FROM employees;
Drag options to blanks, or click blank then click option'
Aemployee_id
Bname
Cdepartment
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY column inside PARTITION BY.
Omitting PARTITION BY when grouping is needed.
3fill in blank
hard

Fix the error in the code to correctly assign row numbers partitioned by department and ordered by hire_date.

SQL
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY [2]) AS rn FROM employees;
Drag options to blanks, or click blank then click option'
Ahire_date
Bemployee_id
Cdepartment
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping PARTITION BY and ORDER BY columns.
Using a non-existent column in either clause.
4fill in blank
hard

Fill both blanks to assign row numbers partitioned by department and ordered by salary descending.

SQL
SELECT employee_id, department, salary, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY salary [2]) AS rank FROM employees;
Drag options to blanks, or click blank then click option'
Adepartment
Bemployee_id
CDESC
DASC
Attempts:
3 left
💡 Hint
Common Mistakes
Using ASC instead of DESC for descending order.
Partitioning by the wrong column.
5fill in blank
hard

Fill all three blanks to select employee name, assign row numbers partitioned by department, ordered by hire_date ascending.

SQL
SELECT [1], ROW_NUMBER() OVER (PARTITION BY [2] ORDER BY [3]) AS row_num FROM employees;
Drag options to blanks, or click blank then click option'
Aemployee_name
Bdepartment
Chire_date
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using salary instead of hire_date for ordering.
Selecting wrong column for employee name.