比如要查处5分钟间隔的人员或设备,或15分钟间隔的人员或设备
思路也简单:按时间排序,按设备或人员分组,查出第二条数据列表,在用exists 进行设备或人员的一条条关联查询,在用每个设备或人员的所有时间去比对第二条数据的时间,如果时间大于5,10分钟,则能查出所要的人员或设备。
select * from device_today dt2 where exists (
select 1 from
(select * from (
SELECT *, ROW_NUMBER() OVER(PARTITION BY device_id ORDER BY time DESC) rn
from device_today
where model_item_id = 't_col'
)t where t.rn = 2) t2
where t2.device_id=dt2.device_id
and dt2.model_item_id='t_col' and dt2.time >= t2.time+5*60 and dt2.time < t2.time+10*60
)