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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sum in bottom row

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

Posted - 2012-05-08 : 16:39:19
Please show us a data example of what your boss wants.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 genre
al jake m
al kelly f
az kim f
az oscar m
ab david m

currently using count(name) as NAME, count(distinct case when genre='m') as male.. etc
so now i need the total sum of the name column and the sum of each genre column at the bottom row
in this case id have a row with
name m f
TOTAL 5 3 2
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

overboard22
Starting Member

13 Posts

Posted - 2012-05-08 : 17:16:47
thank you, will do!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-08 : 19:45:51
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -