<code>//night shift employee
id from_time to_time task
1 21:00:00 22:00:00 - Cleaning(some task)
1 22:00:00 23:30:00 - Fumigation(can be some other task also)
1 4:00:00 7:00:00 - Disinfection
1 2:00:00 4:00:00 - Break
1 23:30:00 2:00:00 - Fogging
//day shift employee
2 09:00:00 10:00:00 - Cleaning(some task)
2 16:00:00 18:30:00 - Disinfection
2 11:30:00 14:00:00 - Fumigation(can be some other task also)
2 14:00:00 16:00:00 - Fogging
2 10:00:00 11:30:00 - Break
</code>
<code>//night shift employee
id from_time to_time task
1 21:00:00 22:00:00 - Cleaning(some task)
1 22:00:00 23:30:00 - Fumigation(can be some other task also)
1 4:00:00 7:00:00 - Disinfection
1 2:00:00 4:00:00 - Break
1 23:30:00 2:00:00 - Fogging
//day shift employee
2 09:00:00 10:00:00 - Cleaning(some task)
2 16:00:00 18:30:00 - Disinfection
2 11:30:00 14:00:00 - Fumigation(can be some other task also)
2 14:00:00 16:00:00 - Fogging
2 10:00:00 11:30:00 - Break
</code>
//night shift employee
id from_time to_time task
1 21:00:00 22:00:00 - Cleaning(some task)
1 22:00:00 23:30:00 - Fumigation(can be some other task also)
1 4:00:00 7:00:00 - Disinfection
1 2:00:00 4:00:00 - Break
1 23:30:00 2:00:00 - Fogging
//day shift employee
2 09:00:00 10:00:00 - Cleaning(some task)
2 16:00:00 18:30:00 - Disinfection
2 11:30:00 14:00:00 - Fumigation(can be some other task also)
2 14:00:00 16:00:00 - Fogging
2 10:00:00 11:30:00 - Break
I need to sort the tasks based from_time in ascending order
<code>SELECT * FROM testing WHERE emp_id='2' ORDER BY from_time ASC
</code>
<code>SELECT * FROM testing WHERE emp_id='2' ORDER BY from_time ASC
</code>
SELECT * FROM testing WHERE emp_id='2' ORDER BY from_time ASC
The above query works fine for day shift employee but not sorting for night shift
<code>SELECT * FROM testing WHERE emp_id='1'
ORDER BY
CASE
WHEN CAST(from_time AS TIME) > '12:00:00' THEN 1
ELSE 2
END,
CAST(from_time AS TIME) ASC;
</code>
<code>SELECT * FROM testing WHERE emp_id='1'
ORDER BY
CASE
WHEN CAST(from_time AS TIME) > '12:00:00' THEN 1
ELSE 2
END,
CAST(from_time AS TIME) ASC;
</code>
SELECT * FROM testing WHERE emp_id='1'
ORDER BY
CASE
WHEN CAST(from_time AS TIME) > '12:00:00' THEN 1
ELSE 2
END,
CAST(from_time AS TIME) ASC;
The above query works fine for night shift emplyee but not sorting for day shift
How can I solve this issue?
I need one query which can sort both night shift and day shift employees tasks based on from_time.
Recognized by PHP Collective
New contributor
Preethi N is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.