Hello, I am stuck figuring out a working SQL Query for the fallowing:
I need to generate a Fire Register report (how many people are still inside the building) based on an Access database that records login/logout events along with some metadata.
The Access DB looks like this:
+----+---------------------+---------+---------+------+ | id | date | action | success | user | +----+---------------------+---------+---------+------+ | 1 | 2009-04-28 02:00:00 | login | 1 | Nick | | 2 | 2009-04-28 03:00:00 | logout | 1 | Nick | | 3 | 2009-04-28 04:00:00 | login | 1 | Nick | | 4 | 2009-04-28 04:00:00 | logout | 1 | Nick | | 5 | 2009-04-28 04:00:00 | login | 1 | Nick | | 6 | 2009-04-28 07:00:00 | login | 1 | John | | 7 | 2009-04-28 07:30:00 | login | 1 | Sue | | 8 | 2009-04-28 08:00:00 | logout | 1 | John | +----+---------------------+---------+---------+------+
During the day there can be multiple login/logout actions.
When administrator runs the report, it's only limited for current day and needs to list all users where the last known action for this user is login
and success=1, meaning that this person is currently in the building.
On the data above, Nick and Sue must be pointed out as still being inside the building.