Jeg gætter på, at du vil finde forskellen mellem min checkin tid (hvor checktype =1) og max checkout tid (hvor 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