Ask Your Question
3

How can I create an SQL Query for generating a report on Time in and Time out using MySQL?

asked 2021-11-03 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-19 09:00:00 +0000

devzero gravatar image

Assuming that you have a table named "attendance" with the following columns:

  • id (unique identifier)
  • employee_id (employee's unique identifier)
  • time_in (datetime when the employee clocks in)
  • time_out (datetime when the employee clocks out)

You can use the following query to generate a report on time in and time out:

SELECT employee_id, DATE(time_in) AS date, TIME(time_in) AS time_in, TIME(time_out) AS time_out
FROM attendance
WHERE time_out IS NOT NULL
ORDER BY employee_id, time_in

This query will get the employee ID, date, time in, and time out for each clock-in and clock-out event in the attendance table. The WHERE clause filters out any records where the time out is null, as those represent times when the employee is still clocked-in. The results will be sorted by employee ID and then by time in, so you can see each employee's clock-in and clock-out times in sequence.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-03 11:00:00 +0000

Seen: 9 times

Last updated: Jul 19 '22