SQL query

  • Is it possible to extract a data in one query?

    table

    id | user_id | punch_in | punch_out |

    1 1 07:00 08:00

    2 1 09:00 10:00

    3 2 07:00 08:30

    4 2 09:00 10:00

    get a user id where time between a previous punch_out and next punch in is one hour (user 1)

    9-8 = 1.

    Is it possible to do it in one query or I need to use some additional table to make calculations?

  • select T.*

    from yourTable T

    join yourTable T2 on T.user_id = T2.user_id

    and dateadd( hour, 1, T.punch_out ) = T2.punch_in

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply