Top 10 on multiple rows

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

I have the following structure.

SIC SalesCode YTD

My database has 200k rows with multiple sics and
SalesCodes.

I would like to structure a query that will go through the
entire database and return the Top Nvalue SalesCodes based
on YTD for every change in SIC.

Any ideas?

Thanks in advance.
 
Hi,


SELECT a.SIC, LAST(a.SalesCode), a.YTD
FROM myTable As a INNER JOIN myTable As b
ON a.SIC=b.SIC
AND b.YTD>= a.YTD
GROUP BY a.SIC, a.YTD
HAVING COUNT(*) <= 10



is a possible solution. Basically, it counts the number of records with a
YTD greater or equal to a.YTD, for a given a.SIC; and keeps those with a
count of 10, or less.


May take some time to run.



Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Top N Values 1
HELP, Create Table o the fly from dataset 2
For Next Loop 1
Update query 2
Increase Formula Cell Selection Based on Value 8
Crosstab Query Rows 6
Ranking multiple Columns 2
Excel Excel Formula OFFSET maybe? 1

Back
Top