Consider the following table structure and sample data -
EmpID InputDateTime StatusINOUT
-------------------------------------
1 2018-05-26 08:44 1
1 2018-05-26 08:44 2
2 2018-05-28 08:44 1
2 2018-05-28 12:44 2
1 2018-05-21 08:44 1
1 2018-05-21 10:44 2
2 2018-05-23 08:44 1
2 2018-05-23 08:44 2
Now I want to separate column InputDateTime
into two columns i.e., INTIME(1)
and OUTTIME(2)
. The logic behind this is the date for which StatusInOut
is 1 will be InTime
and for StatusInOut
is 2 that date value will be OUTTIME(2)
.
The expected output format is as shown below:
Empid INTIME(1) OUTIME(2)
--------------------------------------------
1 2018-05-26 08:44 2018-05-26 08:44
2 2018-05-28 08:44 2018-05-28 12:44
1 2018-05-21 08:44 2018-05-21 10:44
2 2018-05-23 08:44 2018-05-23 08:44
use case when
try:
Try the following query using join and update.
OR you can also try the below one query
Check for the similar answers - here