Problems / Pivot With Row Totals / Editorial
SUM(CASE WHEN category = X THEN amount ELSE 0 END)
ELSE 0
0.00
SUM(amount)
Row totals expose whether a pivot is *self-consistent*. Computing totals in a separate query (or worse, summing the pivoted columns in a wrapper query after each was rounded) invites drift — a category misspelled in one CASE quietly leaks out of its column but stays in the separate total. One GROUP BY producing both the parts and the whole makes the invariant parts sum to total structural rather than hoped-for.
parts sum to total
Solve Pivot With Row Totals yourself →