Sqlite 按时间间隔分组
假设我有一张像这样的桌子 如何创建一个类似于 其中,组是由长度为1秒的时间间隔创建的Sqlite 按时间间隔分组,sqlite,group-by,Sqlite,Group By,假设我有一张像这样的桌子 如何创建一个类似于 其中,组是由长度为1秒的时间间隔创建的 提前谢谢你 这里有一个想法,但你需要一个数字表 select (m.startts + n.n - 1) as starttime, (m.startts + n.n) as enddtime, sum(case when vehicle_type = 'bus' then 1 else 0 end) as bus, sum(case when vehicle_type
提前谢谢你 这里有一个想法,但你需要一个数字表
select (m.startts + n.n - 1) as starttime,
(m.startts + n.n) as enddtime,
sum(case when vehicle_type = 'bus' then 1 else 0 end) as bus,
sum(case when vehicle_type = 'car' then 1 else 0 end) as car
from (select min(Timestamp) as startts from table t) m cross join
(select 1 as n union all select 2 union all select 3) n left join
table t
on t.timestamp >= m.startts + n.n - 1 and
t.timestamp < m.startts + n.n
group by m.startts + n.n;
这是一个有点危险的浮点运算,但它可能会为你的目的工作。难以置信,你只是顺便做了这个。非常感谢你!