Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Totals in Query

Status
Not open for further replies.

eebabe

IS-IT--Management
Jul 17, 2003
54
US
These are my Data:

ID Name Enroll Stats Stat Date
00001 Babe Ruth 1- Enrolled 10/13/07
00001 Babe Ruth 7 - Disenrolled 02/20/07
00001 Babe Ruth 0 - Referred 06/01/06

I want to show the the data that correspont to the last date in the list ie. 00001 Babe Ruth 1- Enrolled 10/13/07. Using query and total I group ID, Name, Enroll Stats and Last for stat date. The query result still shows 3 entries and here's the sql query:

SELECT [tbl Enrollment History].[PC ID], [tbl Enrollment History].Name, [tbl Enrollment History].[Enroll Stats], Last([tbl Enrollment History].[Stat Date]) AS [LastOfStat Date]
FROM [tbl Enrollment History]
GROUP BY [tbl Enrollment History].[PC ID], [tbl Enrollment History].Name, [tbl Enrollment History].[Enroll Stats];

Thanks for your expertise.
 
Select ID, Name, [Enroll Stats], [Stat Date]
From [tbl Enrollment History]

inner join
(Select id,max(Stat Date) as MaxStateDate
From [tbl Enrollment History]
Group by Id)MaxDateById
on MaxDateById.id=[tbl Enrollment History].id
And MaxDateById.MaxStateDate=[tbl Enrollment History].[Stat Date]
 
pwise:

Thanks for the reply. I pasted the query is MS Access and it there's a syntax error (missing operator) in query expression 'max(Stat Date)'.

Do I need to include [tbl Enrollment History].[stat date]?

Thanks.
 
try putting brakkets around Stat date

Code:
Max([COLOR=red][[/color]Stat Date[COLOR=red]][/color])
 
pwise:

I'm sorry. :(

After I put the Max([Stat Date]) another error comes; Syntax error in From clause.

Not sure what's the problem.

Thanks for your help.
 
can you post the SQL that's giving you the error?

Leslie
 
Leslie:

Thanks for your help. I went the long way. I queried (qry_MaxDate)and then link this query to enroll_hist to find the enroll status that connected to the maxDate.

Maybe there's a simpler way but working with access - it's finicky!!

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top