參考~
https://dbfiddle.uk/F_kXR9sR
Select *
,(
select top 1 Value
from t b
where b.Status = 10
and a.MonitorId = b.MonitorId
and a.DateTime > b.DateTime
order by b.DateTime desc
) LAGValue
From t a
order by a.MonitorId
,a.DateTime

iThome鐵人賽