Create a Top N Values per Group Query

cgemmill1

Registered User.
Local time
Yesterday, 20:46
Joined
Jul 16, 2012
Messages
34
I am looking for some assistance in desinging a query that returns the top 4 records for each group. I have a base query that includes HRET_OrganizationID, HRET_MEasureID, Start Date, Numerator, Denominator, and Organization Name. This query serves to pull out the records I am interested in from the larger database.

The query I wrote to pull the top 4 is a select query with the following: HRET_OrganizationID (Ascending), HRET_MEasureID, Start Date (Descending), Numerator, Denominator. Under critieria for Start date I have the following (Select Top 4 [Start Date] from tbl_CDS where [HRET_OrganizationID]=[test21].[HRET_OrganizationID] Order by [Start date] desc)

The result I get is the Top 4 organizations. What I am looking for are the top four months for each group (organization).

Can anyone assist me?
 
Paul, thank you for the response. I have reviewed this article and I am still unable to get the results I am looking for. I even tried not using a query but the actual tables and no luck.
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.9 KB · Views: 401
Last edited:
Is that an underscore after the WHERE?
 
Yes there was and after removing the underscore I was able to get the example to work in the Northwinds database. Using the same logic I applied the fields from my database. The end result is I keep getting asked to enter a value for HRET_OrganizationID
 
The parameter prompt typically means something is spelled wrong. Does the field perhaps have a space rather than an underscore?
 

Users who are viewing this thread

Back
Top Bottom