Saya kira Anda ingin menemukan perbedaan antara waktu checkin min (di mana checktype =1) dan waktu checkout maks (di mana checktype =0)
select userID,
min_date,
max_date,
(max_date - min_date) diff
from (
select distinct userID,
(
select min(checktime)
from checkinout t2
where t1.userID = t2.userID
and t2.checktype = 1
) min_date,
(
select max(checktime)
from checkinout t3
where t1.userID = t3.userID
and t3.checktype = 0
) max_date
from checkinout t1
)
order by userID