这是我的查询导致上述错误。我觉得这是顺序之一,但是哪一个?
select cast(max(DateAndTime) - min(DateAndTime) as time) as DownTime
from (select pt.*,
sum(case when datediff(second, prevdt, DateAndTime) <= 1 then 0 else 1 end) over
(order by DateAndTime) as grp
from (select pt.*, lag(DateAndTime) over (order by DateAndTime) as prevdt
from IncomingProductTracker pt
where Line1AFaultStatus = 1 and
DateAndTime > '2014-04-07 8:00:00' and
DateAndTime < '2014-04-07 17:00:00'
) pt
) pt
group by grp
order by 1;