按时间间隔分组
group by time interval
假设我有一个 table 喜欢
我怎样才能创建一个像
这样的 table
其中组是由长度为 1 秒的时间间隔创建的。
提前致谢!
这是一个想法,但你需要 table 个数字
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;
由于浮点运算,这有点危险,但它可能适合您的目的。
假设我有一个 table 喜欢
我怎样才能创建一个像
这样的 table其中组是由长度为 1 秒的时间间隔创建的。
提前致谢!
这是一个想法,但你需要 table 个数字
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;
由于浮点运算,这有点危险,但它可能适合您的目的。