Top n report

  • Thread starter Thread starter Attila Fust
  • Start date Start date
A

Attila Fust

I have a table that has the following fields:

ID
Cost

I want the query to first group the ID's and sum by the
grouped ID's. Then I want to select the top 10 ID's by
summed cost. When I select a number in the top values box
(eg. 10) the table will return the top 10 ID's (ie. the
ID's with the highest counts).

Is there a way to select the top 10 ID's by summed cost?

Thanks,

Attila Fust
 
SELECT TOP 10
t.ID,
Sum(t.Cost) AS SumOfCost
FROM tblTest AS t
GROUP BY t.ID
ORDER BY Sum(t.Cost) DESC;
 
SELECT TOP 10 ID, SUM(Cost) As SummedCost
FROM table_name
GROUP BY ID
ORDER BY 2 DESC
 
Back
Top