I use access to query a Jet database full of info about members of a club.
Each attendance by each member at any of 18 sites is recorded in a table called qptHisAttendance
I'm trying to create a query that will list each member ID in the first column and the site ID for the site they've visited most in the last 30 days.
So far I've got two queries. The first lists all the visits made by a member in the past 31 days. The next one takes that list and gives a count by site ID
I want a third that just shows the Member ID and the Site ID (for the site that has the highest count in query 2).
Query 1 (called "qryBP_SiteMostVisited1") looks like this:
Expand|Select|Wrap|Line Numbers
- SELECT qptHisAttendance.MemberId, qptHisAttendance.AtDate AS AttendDate, qptHisAttendance.SiteID
- FROM qptHisAttendance
- GROUP BY qptHisAttendance.MemberId, qptHisAttendance.AtDate, qptHisAttendance.SiteID
- HAVING (((qptHisAttendance.MemberId)=13500741) AND ((qptHisAttendance.AtDate)>=Now()-31));
Expand|Select|Wrap|Line Numbers
- SELECT [qryBP_SiteMostVisited1].MemberId, [qryBP_SiteMostVisited1].SiteID, Count([qryBP_SiteMostVisited1].SiteID) AS CountOfSiteID
- FROM [qryBP_SiteMostVisited1]
- GROUP BY [qryBP_SiteMostVisited1].MemberId, [qryBP_SiteMostVisited1].SiteID;
Cheers
Bob