Brug Row_number
at bestille dit bord. Forbind derefter med forrige række for at sammenligne
with cte as (
select
*, row_number() over (partition by [Emp ID] order by time) rn
from
Timecal
)
select
a.[Emp ID], a.time, status = case when datediff(hh, b.time, a.time) < 5 then 0 else 1 end
from
cte a
left join cte b on a.[Emp ID] = b.[Emp ID] and a.rn - 1 = b.rn