SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get SUM
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

xal_kaushi
Starting Member

3 Posts

Posted - 12/21/2012 :  07:35:41  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 12/21/2012 :  07:40:36  Show Profile  Reply with Quote
select status,count(*) from table group by ROLLUP(status)


--
Chandu
Go to Top of Page

xal_kaushi
Starting Member

3 Posts

Posted - 12/21/2012 :  07:42:30  Show Profile  Reply with Quote
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

India
52323 Posts

Posted - 12/21/2012 :  07:46:26  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 12/21/2012 :  07:51:47  Show Profile  Reply with Quote
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 - 12/21/2012 :  08:07:28  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 12/21/2012 :  08:20:28  Show Profile  Reply with Quote
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

India
52323 Posts

Posted - 12/21/2012 :  09:07:21  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.19 seconds. Powered By: Snitz Forums 2000