Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count * in to Column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Muj9
Yak Posting Veteran

United Kingdom
75 Posts

Posted - 08/16/2013 :  08:20:07  Show Profile  Reply with Quote
Hi all,

i have a table which after a count(*) looks like this :-

Fruits total

Apple 2
Banana 8
Orange 5

what i want is to work out the total in to the column so for example:-

Fruits total

Apple 2
Banana 8
Orange 5
All_Fruit 15

Can this be done?
I will be very greatful to anyone who can help me.

Thank you







stepson
Aged Yak Warrior

Romania
545 Posts

Posted - 08/16/2013 :  08:26:07  Show Profile  Reply with Quote
add:

union all

select 'All Fruits',sum(total) as total
from QUERY


Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 08/16/2013 :  08:31:43  Show Profile  Reply with Quote
1) SELECT Fruits, COUNT(*) total 
   FROM TableName
   GROUP BY Fruits
   UNION  
   SELECT 'All_Fruit', COUNT(*) 
   FROM TableName

2) SELECT Fruits, COUNT(*) total 
   FROM TableName
   GROUP BY Fruits WITH ROLLUP


--
Chandu
Go to Top of Page

Muj9
Yak Posting Veteran

United Kingdom
75 Posts

Posted - 08/16/2013 :  08:43:41  Show Profile  Reply with Quote
Hi thank you all for your help.

i used

SELECT Fruits, COUNT(*) total
FROM TableName
GROUP BY Fruits WITH ROLLUP

brilliant.

Thank you
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 08/16/2013 :  08:47:07  Show Profile  Reply with Quote
quote:
Originally posted by Muj9

Hi thank you all for your help.

i used

SELECT Fruits, COUNT(*) total
FROM TableName
GROUP BY Fruits WITH ROLLUP

brilliant.

Thank you


Welcome

--
Chandu
Go to Top of Page
  Previous Topic Topic Next 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.07 seconds. Powered By: Snitz Forums 2000