I use h2 database.
I have 3 tables: USER, SCHEDULEWORKER and SECURITYACCESS.
USER
userNumber, firstName, lastName
SCHEDULEWORKER
USERNUMBER, STARTDATE, ENDDATE
SECURITYACCESS
USERNUMBER, DATEACCESS, DOOR
STARTDATE, ENDDATE and DATEACCESS use timestamp datatype.
I would like to get know all user who suppose to work a day and who entered the maindoor after the start date.
So for this example
SCHEDULEWORKER
USERNUMBER STARTDATE ENDDATE
4141 2012-07-02 07:30:00.0 2012-07-02 16:30:00.0
4123 2012-07-02 07:30:00.0 2012-07-02 16:30:00.0
SECURITYACCESS
USERNUMBER DATEACCESS DOOR
4145 2012-07-02 07:31:56.0 MainDoor
4123 2012-07-02 07:29:56.0 MainDoor
I would like to have
USERNUMBER STARTDATE ENDDATE DATEACCESS DOOR late
4141 2012-07-02 07:30:00.0 2012-07-02 16:30:00.0 2012-07-02 07:31:56.0 MainDoor 00:01:56
Do I need to split my field timestamp to be able to do this query?
It will be slow but if you have many SECURITYACESS in a day you have to compare first access that day.
I don’t work with h2 so you have to manage timestamp calculations for late column
If you have more where conditions: date range maybe or usernumber as parameter you should change MSA query for better performance.
I didn’t found timestamp to date conversion or function for better group by clause.