I have a table that essentially has:
person activity-code activity-value
There are multiple activity-codes (about 17 of them) and activity-values per person. For exmaple:
A 1 10
A 1 12
A 2 4
B 1 5
B 2 3
B 2 8
What I want is a select statement that returns something like:
A 22 4
B 5 11
So the first column is the person. The second column is the sum of all activity-values for the activity-code 1 for that person. The third column is the sum of all activity-values for the activity-code 2 for that person. etc…
In the end I want to do this and use the OUTFILE command in there as I want to dump the totals to a file to be imported into an excel file.
It seems like there is a subquery in there somewhere but I am not advanced enough to figure that out.
Any help would be greatly appreciated. I can add detail if that is going to help.
Unfortunately for you, Mysql lacks the
pivotcommand present in other databases, which makes this sort of thing a piece of cake. You’re stuck with something like