A contrived example to show some clean clode practices as they relate to SQL. In particular, the use of:
- Factoring out logical bits of work into common table expressions (CTE’s) like functions.
- CTE’s with good variable names
- Showing a flat structure to what would otherwise be a highly nested set of SQL statements, which become unreadable quickly