Problems / Rollup Summary / Editorial
Build the result in three layers and combine with UNION ALL:
GROUP BY year, quarter
GROUP BY year
This manual rollup pattern is the foundation of OLAP reporting. SQL's GROUP BY ROLLUP(year, quarter) can produce the same result automatically, but the UNION ALL approach is more explicit and portable.
GROUP BY ROLLUP(year, quarter)
Use unionByName (not union) to match columns by name rather than position, which is safer when column order varies.
unionByName
union
Solve Rollup Summary yourself →