select device_id, speed, count(*) as num_timesfrom (select t.*, row_number() over (partition by device_id order by datetime) as seqnum, row_number() over (partition by device_id, speed order by datetime) as seqnum_s from t ) tgroup by device_id, speed, (seqnum - seqnum_s);
然后,要获得最大值,请使用另一层窗口函数:
select device_id, speed, num_timesfrom (select device_id, speed, count(*) as num_times, row_number() over (partition by device_id order by count(*) desc) as seqnum from (select t.*, row_number() over (partition by device_id order by datetime) as seqnum, row_number() over (partition by device_id, speed order by datetime) as seqnum_s from t) t group by device_id, speed, (seqnum - seqnum_s) ) dswhere seqnum = 1;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)