Question : Earliest and latest times each day - mdb query

I've a table "Times" which contains a Date/Time field "DT" and a Date Field "Date" Together with Text fields "User" and "Site" and a flag for "AM/PM".

The table is populated by another query and contains about a month's worth of data about activity

I'm trying to prodice a query that will return the first and last time value from "DT" for AM & PM on each "Date" so I can get start and end times for morning and afternoon for each"User" by the "Site" they were at.

Ultimately I am looking for an output which is along the lines of:

User A  | Site 2| 04/01/2009| AM| 07:55 | 11:29
User A  | Site 2| 04/01/2009| PM| 13:50 | 16:53


I've been playing with SELECT MIN.... AS ... FROM etc and can see glimpses of what I need but I am well outside my comfort zone.


Anyone who has been patient enough to talk me through queries in the past will know that once I leave Access' Drag and Drop Query design I start to struggle but I do learn quickly (and so I'm not here that often) so please be patient!

Happy to do this in stages if that will be easier to grasp.

Please try to avoid VB but I can manage MS-SQL

Thanks :)

Answer : Earliest and latest times each day - mdb query

MASQUERAID,

If you already have that AM/PM...

SELECT User, Site,[Date], [AM/PM], Min(DT) AS FirstTime, Max(DT) AS LastTime
FROM [Times]
WHERE DT <#12:00 PM#
GROUP BY User, Site, [Date], [AM/PM]
UNION ALL
SELECT User, Site,[Date], [AM/PM], Min(DT) AS FirstTime, Max(DT) AS LastTime
FROM [Times]
WHERE DT >=#12:00 PM#
GROUP BY User, Site, [Date], [AM/PM]

Regards,

Patrick
Random Solutions  
 
programming4us programming4us