I have the following SQL query...
SELECT TOP 5 SumOfTotal, Year, Customer
FROM Reporting_MonthlyTotalSales
GROUP BY Reporting_MonthlyTotalSales.SumOfTotal, Reporting_MonthlyTotalSales.Year, Reporting_MonthlyTotalSales.Customer
ORDER BY Reporting_MonthlyTotalSales.SumOfTotal DESC
This returns to me the TOP 5 highest annual SALES totals, by CUSTOMER ie.
1999 - 200,000 Cust 1
1999 - 180,000 Cust 25
2002 - 175,000 Cust 3
2010 - 130,000 Cust 49
2004 - 120,000 Cust 1
But what I actually want is : the TOP 5 sales totals (an thus the Top 5 Customers), for EACH YEAR.
Help gratefully received, thank you.
==================
Addendum: having posted this elsewhere and having no luck in terms of anyone suggesting an alternative to methods I have tried.... I attach a screenshot of a traditional example I have used that causes Access to get stuck in a loop.
I have also tried the following Ranking query suggested on another thread of this site... but clearly I have something wrong... because it doesnt return what is expected....
SELECT *
FROM (SELECT a1.SumOfTotal, a1.Customer, a1.Year, COUNT(*) AS CategoryRank
FROM Reporting_AnnualSalesByCustomer AS a1 INNER JOIN Reporting_AnnualSalesByCustomer AS a2
ON (a1.CUSTOMER = a2.CUSTOMER) AND (a1.SumOfTotal<= a2.SumOfTotal)
GROUP BY a1.SumOfTotal, a1.Customer, a1.Year
) AS RankingQuery
WHERE (((RankingQuery.[CategoryRank])<=5) )
ORDER BY RankingQuery.SumOfTotal, RankingQuery.Customer, RankingQuery.Year;
Hope someone can help.. having spent most of today on it... its doing my head in....!
Thank you,