I suspect that what you are trying to do is a lot simpler than that: the number of items in the
GROUP BY
clause screams "I'm guessing because it won't let me use these fields unless I list them all"
GROUP BY
creates a new group for each column in the clause: so if you have a basic table:
A B C
1 1 1
1 1 2
1 2 3
1 2 4
2 1 1
2 1 2
2 2 3
2 2 4
Then
GROUP BY A
will create two groups (A == 1 and A == 2)
But
GROUP BY A, B
will create 4 groups (A == 1 and B == 1, A == 1 and B == 2, A == 2 and B == 1, A == 2 and B == 2)
So your
GROUP BY
clause will probably generate nearly as many groups as there are rows in your table!
I'd suggest that you sit down, look at your data, and think about what output you are trying to get - and then try to build it up in easy chunks. Because just dashing in there and hoping it will work isn't going to! :laugh:
And that looks a lot like what you have been trying to do.