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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count * in to Column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Muj9
Starting Member

United Kingdom
31 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
Constraint Violating Yak Guru

Romania
278 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
2168 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
Starting Member

United Kingdom
31 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
2168 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  
 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.05 seconds. Powered By: Snitz Forums 2000