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
 Transact-SQL (2000)
 Sum Top X

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-08-29 : 07:53:31
Doug Villhard writes "How do you sum the top x rows in a query?"

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-08-29 : 08:02:13
You could use a derived table:

SELECT SUM(Sales) AS SumOfSales FROM
(
SELECT TOP 10 ProductID, SUM(Sales) AS Sales
FROM Product_Sales
GROUP BY ProductID
ORDER BY SUM(Sales)
) A

Owais


Make it idiot proof and someone will make a better idiot
Go to Top of Page
   

- Advertisement -