Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
overboard22
Starting Member
13 Posts |
Posted - 2012-05-08 : 16:38:10
|
| alright so my boss asked me to get the total of each columns at a row in the bottom. thing is my queries are already huge, and the values are varchar so first i have to do the count case and after that the sum of everything or something, anyways, i was just wondering if this is done very often in sql or if its better to just use a tool like excel to get totals. thanks for your help! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-08 : 16:44:41
|
| sounds like a cross tabbing query request for me------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
overboard22
Starting Member
13 Posts |
Posted - 2012-05-08 : 16:48:58
|
| ok im gonna write a quick/easy example based on my tables:place name genreal jake m al kelly f az kim f az oscar mab david mcurrently using count(name) as NAME, count(distinct case when genre='m') as male.. etcso now i need the total sum of the name column and the sum of each genre column at the bottom rowin this case id have a row with name m fTOTAL 5 3 2 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-08 : 17:00:51
|
| have a look at WITH CUBE and WITH ROLLUP options------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
overboard22
Starting Member
13 Posts |
Posted - 2012-05-08 : 17:16:47
|
| thank you, will do! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-08 : 19:45:51
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|