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
 Adding values of a column

Author  Topic 

arbaaz_Khan
Starting Member

3 Posts

Posted - 2009-09-11 : 12:47:32
Below is the table returned from the sql query. I need to add up all the values of the numbers column. I am having a hard time in doing that...Can anyone help me plzz


Select Count(distinct activity_id, type) as numbers,activity_id, type
FroM table1
Group by activity_id
having numbers > 1

numbers activity_id type
23 jkj soft
1 jjkp hard

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-11 : 14:14:55
select count(*) as numbers, activity_id, type
from table1
group by activity_id, type
having count(*) > 1

If that is not what you want be a bit more clear please.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

arbaaz_Khan
Starting Member

3 Posts

Posted - 2009-09-11 : 16:17:35
Okay...the query below works fine
--------------
Select Count(distinct activity_id, type) as numbers,activity_id, type
FroM table1
Group by activity_id
having numbers > 1
-------------------

It creates a column named as numbers. I need to get the sum on the values of the fields in that column.


For example...from the above table it should add up fields 23 and 1 from columns numbers and output it

numbers activity_id type
23 jkj soft
1 jjkp hard

I hope I made it clear this time.

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-11 : 16:30:39
select sum(numbers) from
(Select Count(distinct activity_id, type) as numbers,activity_id, type
FroM table1
Group by activity_id
having numbers > 1
)dt


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

arbaaz_Khan
Starting Member

3 Posts

Posted - 2009-09-11 : 16:38:07
Thanks a lot...that's what I was looking for
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-11 : 16:39:27
fine


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -