I am trying to write a top n value query in Microsoft Access where n may change by group. For example, one group may be top 3 records, another may be top 2 records, and another may be top 4 records. I have a table with the field "TopN" where I store how many values to show for that group.
Sample of Top 3 query that works, I am trying to replace Top 3 with Top N where N is a DLookup or something that uses the value in TopN field:
SELECT Payout.GDate, Payout.[Game Type], Payout.Denom, Payout.Segment, Payout.Manufacturer_Description, Payout.Stand, Payout.Payout
FROM Payout, PayoutShowSegment
WHERE (((Payout.Payout) IN (SELECT TOP 3 [Payout]
FROM [Payout]
WHERE [Payout].[Segment]=[PayoutShowSegment].[Segment])))
ORDER BY Payout.[Game Type], Payout.Denom, Payout.Payout DESC;