Module 02 · Lesson 8 of 12Pro
Recursive queries: hierarchies and graphs in SQL
- Level
- Advanced
- Reading time
- 18 min
When you finish this page you can
- Write a WITH RECURSIVE query from its three parts, an anchor, a step and a stop, and trace it round by round.
- Walk a category tree down and up, with a depth and a readable path for every category.
- Roll revenue up to every level of a tree of any depth, counting each sale once per ancestor.
- Stop cycles in bad tree data, and decide when to build a closure table in the pipeline instead of recursing in every report.