Why can adjacent BETWEEN windows double-count a timestamp?
BETWEEN includes both endpoints. Half-open adjacent intervals assign their shared boundary to just one interval.
SQLite example and interpretation
Second ten qualifies for both inclusive ranges zero to ten and ten to twenty. Use a consistent inclusive start and exclusive end for hourly accounting.
SELECT 10 BETWEEN 0 AND 10,10 BETWEEN 10 AND 20,10>=0 AND 10<10;Result [[1, 1, 0]]
中文
为什么相邻两个 BETWEEN 时间窗会重复统计边界?
BETWEEN 包含上下端点。将连续区间定义为左闭右开,能让交界时刻只归入一段。
SQLite 示例与适用条件
秒数 10 同时满足 0 到 10 和 10 到 20 的 BETWEEN。按小时结算应统一使用 >= 起点与 < 终点。
SELECT 10 BETWEEN 0 AND 10,10 BETWEEN 10 AND 20,10>=0 AND 10<10;结果 [[1, 1, 0]]