I have table Att_Log like this:
| Emp_ID | Date_Att | Time_Att |
|---|---|---|
| E-0123 | 2024-01-02 | 08:05:56 |
| E-0123 | 2024-01-02 | 17:02:23 |
| E-0124 | 2024-01-02 | 21:55:56 |
| E-0124 | 2024-01-03 | 06:02:23 |
the results I expect is like this:
| Emp_ID | Date | In_Time | Out_Time |
|---|---|---|---|
| E-0123 | 2024-01-02 | 08:05:56 | 17:02:23 |
| E-0124 | 2024-01-02 | 21:55:56 | 06:02:23 |
get the min(Time_Att) as Out_Time from following Date_Att if the In_Time is >= 21:00:00
How to query in MySQL server?
I can query the min and max Time_Att with this query:
SELECT Emp_ID, Date_Att, Min(Time_Att) AS InTime, Max(Time_Att) AS OutTime FROM Att_Log
but I don't know how to get the above result. If anyone can help, I would highly appreciate it. Thank you in advance.
Probably not what you want but gives your expected result for the sample data in your question.
(Assumes data type of column DATE_ATT is DATE and data type of TIME_ATT column is TIME. Refer to MySQL documentation.)
Refer to this db<>fiddle and these SO questions: