Top 25 by category

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here is the scenario. we have a few thoushand items that are grouped into a
few dozen categoreis. I need to write a query that will return the top 25
items by sales for each categorey.
 
Probably you will need to use a coordinated subquery.

I don't know from your posting whether you want the top 25 by the number of
items sold, the dollar value of the items, or the number of sales where the item
was one of the items sold (that is the number of sales involving the item).


SELECT Category, Item
FROM YourTable
WHERE Item IN (

SELECT TOP 25 Item
FROM YourTable as T25
WHERE T25.Category = YourTable.Category
GROUP BY Items
ORDER BY Count(T25.Sales) Desc)
 
Back
Top