You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL滑动窗口按秒统计计数异常问题求助

滑动时间窗口统计结果异常问题

使用滑动时间窗口统计时,小时级窗口能返回正确结果:

select max(cnt) from (
        select count(*) over w as cnt from cdr
        window w as ( order by calldate range between interval '1' hour preceding and current row)
    ) as a

上述SQL返回正确值57。

但将时间间隔改为1秒后,SQL返回结果为8,实际数据中却不存在同一秒内有8条记录的情况,对应SQL如下:

select max(cnt) from (
        select count(*) over w as cnt from cdr
        window w as ( order by calldate range between interval '1' second preceding and current row)
    ) as a

数据示例

id, id_sensor, calldate
19953276,19,2023-09-01 08:27:42
...
20036310,19,2023-09-04 18:26:29

内容的提问来源于stack exchange,提问作者James Lin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 19:20:02