Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:52:24+00:00 2026-06-14T06:52:24+00:00

I use h2 database. I have 3 tables: USER, SCHEDULEWORKER and SECURITYACCESS. USER userNumber,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:52:25+00:00Added an answer on June 14, 2026 at 6:52 am

    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

    select SW.USERNUMBER, STARTDATE, ENDDATE, DATEACCESS, DOOR, (h2 calculations on timestamps) as late
    FROM SCHEDULEWORKER AS SW 
      inner join SECURITYACCESS AS SA on SW.USERNUMBER=SA.USERNUMBER
      inner join (SELECT USERNUMBER, MIN(DATEACCESS) as ACCESS
                  FROM SECURITYACCESS 
                  GROUP BY USERNUMBER, YEAR(DATEACCESS), DAY_OF_YEAR(DATEACCESS)) AS MSA ON SW.USERNUMBER = MSA.USERNUMBER AND MSA.ACCESS = SA.DATEACCESS
    WHERE SW.STARTDATE < MSA.ACCESS
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone have a PL-SQL statement that i can use to generate database & tables
In my Rails application, I have a variety of database tables that contain user
My database contains 3 tables: User and Service entities have many-to-many relationship and are
Think Design: I have many applications that share the same user database! Other tables
I have a database table which is full-text indexed and i use the CONTAINS-function
Where I have more than one table in my database for use with (similar,
I have to use oracle database in android. I have tried to work as
I am working on an android app and have to use remote database for
I have to use CoreData based database to store my data. At high-level my
i have a database fill with information of the users who use my webpage.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.