Hi can someone help me with a crosstab problem? It may be it can be acheived without a crosstab but with some clever SQL instead but I cant seem to work it out
I have a group of people who are producing stats each month,so for the month of January I have a table (tblstats) with something along the lines of
Username stats1 stats2 stats3 stats4 stats5
John 5 9 4 5 10
Joe 7 4 5 1 3
Jane 10 3 2 6 8
and the same again for February
Username stats1 stats2 stats3 stats4 stats5
John 6 9 4 5 10
Joe 8 4 5 1 3
Jane 9 5 2 6 8
and again for March etc.
I need to get the totals for each user for stats 1, 3 and 5. So for John and stats1 it would be 5+6+march+april etc, and then the same again for stats 3 and then stats5. In the end, for the whole year, I would have something like
Username stats1 stats3 stats5
John 102 103 123
Joe 112 97 106
Jane 111 102 98
I can run a query no problem with
Select tblstats.username,tblstats.stats1,tblstats.stats3,tblstats.stats5
From tblstats;
From this I get multiple entries for each user i.e. the user John appears 12 times (once for each month of the year) as does all the other users. I tried using something to the effect of
tblstats.username,sum(tblstats.stats1) AS stats1, sum(tblstats.stats3) AS stats3, sum(tblstats.stats5) AS stats5
From tblstats;
But needless to say that doesnt work!
I've tried doing a crosstab query and that will give me the username just the once but I cant get it to give me the totals for more than one column. I assume this has something to do with the Transform statement but I'm not very familiar with crosstabs.
Can someone help me with what I need to put in to acheive what I need to do?
many thanks if you can
Steve
I have a group of people who are producing stats each month,so for the month of January I have a table (tblstats) with something along the lines of
Username stats1 stats2 stats3 stats4 stats5
John 5 9 4 5 10
Joe 7 4 5 1 3
Jane 10 3 2 6 8
and the same again for February
Username stats1 stats2 stats3 stats4 stats5
John 6 9 4 5 10
Joe 8 4 5 1 3
Jane 9 5 2 6 8
and again for March etc.
I need to get the totals for each user for stats 1, 3 and 5. So for John and stats1 it would be 5+6+march+april etc, and then the same again for stats 3 and then stats5. In the end, for the whole year, I would have something like
Username stats1 stats3 stats5
John 102 103 123
Joe 112 97 106
Jane 111 102 98
I can run a query no problem with
Select tblstats.username,tblstats.stats1,tblstats.stats3,tblstats.stats5
From tblstats;
From this I get multiple entries for each user i.e. the user John appears 12 times (once for each month of the year) as does all the other users. I tried using something to the effect of
tblstats.username,sum(tblstats.stats1) AS stats1, sum(tblstats.stats3) AS stats3, sum(tblstats.stats5) AS stats5
From tblstats;
But needless to say that doesnt work!
I've tried doing a crosstab query and that will give me the username just the once but I cant get it to give me the totals for more than one column. I assume this has something to do with the Transform statement but I'm not very familiar with crosstabs.
Can someone help me with what I need to put in to acheive what I need to do?
many thanks if you can
Steve