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.
| Author |
Topic |
|
Three Rings
Starting Member
1 Post |
Posted - 2006-03-22 : 16:06:56
|
| Dear All,I have some raw data that look like this:TYPE QUANTITY---- --------A 1B 3C 5A 1B 3C 5A 1B 3C 5What I need is an SQL statement that will return the single value 9.That is, an SQL statement that DISTINCTs the values down to:TYPE QUANTITY---- --------A 1B 3C 5and then SUMs them:-9Can it be done? Any help greatly appreciated.I am using SQL*Server... I haven't checked the version but I would prefer a solution which doesn't rely on proprietary functions - if possible.Many thanks in advance.Best regards,Three Rings |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-03-22 : 16:15:11
|
is this what you're looking for?select sum(quantity)from (select distinct type, quantity from <myTable>) a Be One with the OptimizerTG |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-23 : 01:32:49
|
| orSelect sum(distinct quantity) from yourTableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|