Wednesday, 21 August 2013

How to subtotal multiple columns

How to subtotal multiple columns

I am writing a voting contest where people get to vote for their 1st, 2nd,
3rd and 4th favorite bands. I end up with a table like this:
first second third fourth
band1 band2 band3 band4
band1 band2 band4 band3
band4 band3 band2 band1
What I would like to retrieve is a view showing the subtotal votes for
each band like this:
first second third fourth
band1 2 0 0 1
band2 0 2 1 0
band3 0 1 1 1
band4 1 0 1 1
I tried using GROUP BY with ROLLUP but I am not getting what I need. There
are a variable amount of bands.
How can I accomplish this? TIA

No comments:

Post a Comment