Three tools solve what plain GROUP BY cannot: LATERAL runs a subquery or function per row, recursive CTEs walk hierarchies, and generate_series makes rows the data lacks, such as days on which nothing sold.
MENU
LATERAL, CTEs, generate_series
LATERAL Joins, Recursive CTEs and generate_series for Analytics