SQL practice: Recursive CTEs: Queries That Call Themselves
Chapter 36 · 9 questions · included in full access
Question 1 · easy
Solve it in your browserUse a recursive CTE to produce the numbers 1 to 10, in a single column named n.
Question 2 · easy
Solve it in your browserProduce every date in January 2024 as a column named day, using a recursive CTE.
Question 3 · medium
Solve it in your browserWalk the employee hierarchy from the top down. Show employee_name and level, where the people with no manager are level 1. Order by level, then name.
Question 4 · medium
Solve it in your browserShow each employee with a breadcrumb path from their top-level manager, like "Rajesh Kumar > Anita Sharma", in a column named path. Order by path.
Question 5 · medium
Solve it in your browserCount how many people sit at each level of the hierarchy. Return level and people, ordered by level.
Question 6 · medium
Solve it in your browserList everyone who reports to Rajesh Kumar, directly or indirectly. Show employee_name, ordered by name. Do not include Rajesh himself.
Question 7 · medium
Solve it in your browserStarting at 1, keep doubling until the value passes 1000. Return the values in a column named n, in order.
Question 8 · hard
Solve it in your browserFor every branch manager, list their team: show manager_name, employee_name and level, ordered by manager_name then employee_name. A manager appears as level 1 with their own name in both columns.
Question 9 · hard
Solve it in your browserA recursive CTE that walks a hierarchy has no WHERE clause in its recursive step, and the data contains a cycle: A manages B, and B manages A. What happens?
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing