I'm trying to sum columns in a table and then return each column and value as a separate row, but only if the sum is > 0. Here's an example table
… stuff widget toast …
- ----- ------ ----- -
… 0 0 1 …
… 1 0 3 …
… 2 0 1 …
… 0 0 1 …
… 0 0 0 …
Summing the columns is easy enough
select sum(stuff) as stuff, sum(widget) as widget, sum(toast) as toast from table
Which produces this output
stuff widget toast
----- ------ -----
3 0 6
But what I actually want to end up with is this (notice that widget is missing since the sum is 0)
thing count
---- -----
stuff 3
toast 6
Any advice?