Get subtotals with ROLLUP+GROUP BY

π™π™Šπ™‡π™‡π™π™‹ generates extra rows that represent the subtotals.

For example…

To get the sum of spending of each user, you typically GROUP BY user_id and SUM spend.

Want to get the sum of ALL users in the same result? Try ROLLUP.

πŸ“Œ The syntax is here.
πš‚π™΄π™»π™΄π™²πšƒ
πš„πšœπšŽπš›_πš’πš, πš‚πš„π™Ό(πšœπš™πšŽπš—πš)
π™΅πšπ™Ύπ™Ό
πš„πšœπšŽπš›πšœ
π™Άπšπ™Ύπš„π™Ώ π™±πšˆ πšπ™Ύπ™»π™»πš„π™Ώ(πšžπšœπšŽπš›_πš’πš)

The result will contain a NULL user_id which contains the sum of spend of all users.

πŸš€ In the demo below, we do a roll-up of two aggregation columns, and show the use of a partial roll-up. Check it out.

Bonus point if you can spot the mistake in the demo below.