Using Grouping and MAX funciton

T

tc

I want to select the last entry in the table called LastTwoDays for
each PC ( PCNAME) with that selection I need all 3 fields EVENT,
PCNAME, and EVENT_TIME. The record contains the fields PCNAME, EVENT,
and EVENT_TIME. The query below was working for a while then just
seemed to stop. Now the EVENT name is not correct with the EVENT_TIME.
Any on have any ideas. I think I just need to start over.


SELECT LastTwoDays.PCNAME, Last(LastTwoDays.EVENT) AS LastOfEVENT,
Max([LastTwoDays]![ENTRY_TIME]) AS MaxOfDATE
FROM LastTwoDays
GROUP BY LastTwoDays.PCNAME;
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Last() is a pretty useless function. In general don't use it.

If by "last entry in the table," you mean the record with the latest
Event_Time, then try this:

SELECT DISTINCTROW PCNAME, Event, Event_Time
FROM LastTwoDays As A
WHERE Event_Time = (SELECT MAX(Event_Time) FROM LastTwoDays
WHERE PCName = A.PCName)

The subquery will get the latest Event_Time for the current record in
the main query and the main query will retrieve all the data for the
record that has that Event_Time. If there is more than one record with
the same Event_Time, all of them will be selected.

==
Note: In SQL statements don't use the exclamation point between table
names and column names; use the period instead.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYE58IechKqOuFEgEQKx5QCgxh82ROo/PcB8UuAexgj4tenvMOwAoPd1
b5d1BsPg9QDlQ1iQZ0VtNztx
=u1vi
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top