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
 How to get SUM

Author  Topic 

xal_kaushi
Starting Member

3 Posts

Posted - 2012-12-21 : 07:35:41
Hi All,
i have a table and i want count as well as sum together eg below

Status ----Count
1 ---- 2
2 ----- 3
3 ---- 4
4 ---- 5
Total ---- 14
i want this output how to get it pls help me
for count i am using this query
select status,count(*) from table group by status

pls let me know which query is used to generate above output.

thanks in advance :)

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-21 : 07:40:36
select status,count(*) from table group by ROLLUP(status)


--
Chandu
Go to Top of Page

xal_kaushi
Starting Member

3 Posts

Posted - 2012-12-21 : 07:42:30
quote:
Originally posted by bandi

select status,count(*) from table group by ROLLUP(status)


--
Chandu



HI Chandu
thanks for info pls tell me what is rollup for ??
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-21 : 07:46:26
see

http://chiragrdarji.wordpress.com/2008/09/09/group-by-cube-rollup-and-sql-server-2005/

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

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-21 : 07:51:47
ROLLUP is used to get sub totals for each group and also grand total (means to do aggragate operations on each group of data...)

In your case, it will give count for each group of status and also grand total

You can understand better by following this link:
http://blog.sqlauthority.com/2010/02/24/sql-server-introduction-to-rollup-clause/

--
Chandu
Go to Top of Page

xal_kaushi
Starting Member

3 Posts

Posted - 2012-12-21 : 08:07:28
HiAll
it is showing error undefined function is it work in toad also oracle
or it should be used with case statement only .
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-21 : 08:20:28
quote:
Originally posted by xal_kaushi

HiAll
it is showing error undefined function is it work in toad also oracle
or it should be used with case statement only .


In oracle also there is Rollup function...
This is SQL Server related forums. You can get better and quick solutions from Oracle forums like www.dbforums.com

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-21 : 09:07:21
quote:
Originally posted by xal_kaushi

HiAll
it is showing error undefined function is it work in toad also oracle
or it should be used with case statement only .



whats the error? Did you try it in SSMS also?
whats need of CASE statement?
If you're running against Oracle DB then better to post in relevant forums


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

Go to Top of Page
   

- Advertisement -