0
0
MySQLquery~10 mins

Window functions (ROW_NUMBER) in MySQL - 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 row number to each employee ordered by their salary.

MySQL
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'
Asalary
Bhire_date
Cdepartment
Demployee_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that does not exist in the table.
Forgetting to specify the ORDER BY clause inside OVER().
2fill in blank
medium

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

MySQL
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY salary DESC) AS dept_rank FROM employees;
Drag options to blanks, or click blank then click option'
Aemployee_id
Bsalary
Chire_date
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY column in PARTITION BY instead of grouping column.
Not using PARTITION BY when needed.
3fill in blank
hard

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

MySQL
SELECT employee_id, department, ROW_NUMBER() OVER (PARTITION BY department ORDER BY [1]) AS hire_rank FROM employees;
Drag options to blanks, or click blank then click option'
Ahire_date
Bdepartment
Cemployee_id
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Ordering by a column unrelated to hire date.
Using PARTITION BY incorrectly.
4fill in blank
hard

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

MySQL
SELECT employee_id, department, salary, ROW_NUMBER() OVER (PARTITION BY [1] ORDER BY [2] ASC) AS salary_rank FROM employees;
Drag options to blanks, or click blank then click option'
Adepartment
Bemployee_id
Csalary
Dhire_date
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up partition and order columns.
Forgetting to specify ASC for ascending order.
5fill in blank
hard

Fill all three blanks to assign row numbers partitioned by department, ordered by salary descending, and select employee name.

MySQL
SELECT [1], department, salary, ROW_NUMBER() OVER (PARTITION BY [2] ORDER BY [3] DESC) AS rank FROM employees;
Drag options to blanks, or click blank then click option'
Aemployee_name
Bdepartment
Csalary
Demployee_id
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting wrong columns for employee name.
Confusing partition and order columns.