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 2000 Forums
 SQL Server Development (2000)
 SUM question

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-09-27 : 11:54:34
I have the following query:

SELECT TOP 10 SicDescription, COUNT(*) AS [TotalAccounts], SUM(AccountMV)AS [AccountMV], sum(AccountFeeLY) as AccountFeeLY, sicid
FROM SnapsRaw
WHERE (Branchstate = @state) AND (SicID <> '00') AND (SicID <> '99') AND (monthend = @date)
GROUP BY SicID, SicDescription, MonthEnd
order by accountmv desc

I want to be able to right something that I can than sum up the top 10's sum values, so basically i have the top 10 of something , each with a marketvalue, i want to than add up all those market value and produce the result.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-27 : 11:59:12
???

select sum(somecolumn) where pk_column in (select top 10 pk_column from sometable where ... order by...)
from mytable

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -