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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count * in to Column

Author  Topic 

Muj9
Yak Posting Veteran

75 Posts

Posted - 2013-08-16 : 08:20:07
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

545 Posts

Posted - 2013-08-16 : 08:26:07
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-16 : 08:31:43
[code]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 [/code]

--
Chandu
Go to Top of Page

Muj9
Yak Posting Veteran

75 Posts

Posted - 2013-08-16 : 08:43:41
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-16 : 08:47:07
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
   

- Advertisement -