I'm having troubles with writing a query in Microsoft Access. This is how my table looks like and where i want to retrieve data from:
I want to write a query that has the following result:
As you can see in the first table an employee can check IN and OUT more than 2 times a day. When a employee checks in for the first time the Date/time should be placed in the first colum "CheckIn". When he checks in for the second time the Date/time should be placed in the second column "CheckOut". When he checks in for the 3th time the Date/time should be placed in the column "CheckIn" and so on.
I have learned from my previous question that I can use a subquery and the modulus operator for a similar situation like this. But I can't figure out how i can make the query work for the problem above.
Let's start with the answer from the previous question, and work our way from there.
This query defines if it's a check in, or check-out. Let's call it qryCheckInOut
Then, we can get the check-ins from that query, and use a subquery to get the check-outs.
We use conditions to make sure the check out is on the same day, and later than the check in, and use the
Min
aggregate to make sure it's the next time (the lowest possible time).Note that, in the subquery of the second query, you don't need to check if it's a check in or check out, since the lowest time higher than the check in on the same day always is a check out.
If you want to do it in a single query, you can use the query below. However, it will be substantially harder to debug