Chapter Practice Arena
All ChaptersAdvanced SQL Queries Problems
Targeted practice challenges specifically curated for this chapter. Inspect hints, verify outputs, and check verified solutions.
Filter by Language:12 Problems
Filter by SQL Chapter:
Difficulty:
Chapter:
Showing 6 challenges · 12 total · Page 1 of 2
Practical Example: Rank Employees by Salary
Starter Code
-- Practice query for Ranking with ROW_NUMBER, RANK, and DENSE_RANK
Expected Output
Formatted Result| employee_id | employee_name | department | salary | row_num | salary_rank | salary_dense_rank |
|---|---|---|---|---|---|---|
| 1 | Asha | Engineering | 90000 | 1 | 1 | 1 |
| 2 | Ravi | Engineering | 85000 | 2 | 2 | 2 |
| 3 | Meera | Engineering | 85000 | 3 | 2 | 2 |
| 5 | Neha | Sales | 75000 | 1 | 1 | 1 |
| 4 | Kabir | Sales | 70000 | 2 | 2 | 2 |
5 rows returned7 columns
Real-World Example: Employee Management Hierarchy
Starter Code
-- Practice query for Recursive CTEs
Expected Output
Formatted Result| employee_id | employee_name | manager_id | depth | path |
|---|---|---|---|---|
| 1 | Asha | NULL | 0 | {1} |
| 2 | Ravi | 1 | 1 | {1,2} |
| 3 | Meera | 1 | 1 | {1,3} |
| 4 | Arjun | 2 | 2 | {1,2,4} |
| 5 | Neha | 2 | 2 | {1,2,5} |
| 6 | Kabir | 3 | 2 | {1,3,6} |
6 rows returned5 columns
Cycle Detection in Hierarchical Data
Starter Code
-- Practice query for Recursive CTEs
Expected Output
Formatted Result| node | path |
|---|---|
| 1 | {1} |
| 2 | {1,2} |
| 3 | {1,2,3} |
3 rows returned2 columns
5. Use CTEs with Filtering and Aggregation
Starter Code
-- Practice query for Common Table Expressions (CTEs)
Expected Output
Returns customers whose total amount across completed orders is at least 1000. Exact results depend on the schema, status values, and stored amounts.
PARTITION BY: Calculate Within Groups
Starter Code
-- Practice query for Window Functions
Expected Output
Formatted Result| sale_id | employee | amount | employee_total |
|---|---|---|---|
| 1 | Asha | 100 | 250 |
| 2 | Ravi | 200 | 500 |
| 3 | Asha | 150 | 250 |
| 4 | Ravi | 300 | 500 |
4 rows returned4 columns
Top N With Ties: RANK and DENSE_RANK
Starter Code
-- Practice query for Ranking with ROW_NUMBER, RANK, and DENSE_RANK
Expected Output
Formatted Result| employee_name | salary | salary_rank | salary_dense_rank |
|---|---|---|---|
| Asha | 100000 | 1 | 1 |
| Meera | 90000 | 2 | 2 |
| Ravi | 90000 | 2 | 2 |
3 rows returned4 columns