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)
 How to add together particular values in a column

Author  Topic 

algorithm
Starting Member

6 Posts

Posted - 2008-07-18 : 15:44:14
I presume this is possible to do in SQL Server, but I can't figure it out.

I have a table which is something like this
Number Weighting
1234 1
6789 1
1234 1
6789 0.5
3456 0.5
7890 0.5
1234 0.1

Basically it is a finite list of 'Numbers' (approx 30 variations), with associated weightings. Each of the 'Numbers' is stored in a seperate table, say Number_List. There ARE duplicate rows, which I know that we hate that, it's ok for me here.

So what I want to do is write a query does something like;
- for each entry in Number_List (i.e. each number)
- add together the weighting

So at the end I wish to be left with a list of the numbers and the grand-total of the 'Weightings'.

Does this make sense? I'd be really grateful for any guidance on this.

Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-18 : 15:45:50
SELECT Number, SUM(Weighting) AS Weighting
FROM YourTable
GROUP BY Number

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

algorithm
Starting Member

6 Posts

Posted - 2008-07-18 : 16:19:09
Wow Tara - you're a genius. Thanks SO much, I spent a while trying to figure this out. I really really appreciate this.
quote:
Originally posted by tkizer

SELECT Number, SUM(Weighting) AS Weighting
FROM YourTable
GROUP BY Number

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-18 : 16:40:07
No genius knowledge needed for this one.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -