Anurag Deokar Anurag Deokar - 21 days ago 4x
SQL Question

My sql query is not getting desier result

enter image description here

These is my attendance table checktype 0 is use as intime and 1 as out time,
i want time as intime for checktype = 0 and time as outtime for checktype = 1
with single entry according date with all empid order by intime will be ascending
for checktype 0 and descending for checktype 1

i want below type result

enter image description here


Here's a way to select the smallest intime and largest outtime for each employee per day:

select min(case when checktype = 0 then time end) min_intime,
    max(case when checktype = 1 then time end) max_outtime,
from mytable
group by empid, date