Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 按时间间隔分组_Sqlite_Group By - Fatal编程技术网

Sqlite 按时间间隔分组

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

假设我有一张像这样的桌子

如何创建一个类似于

其中,组是由长度为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 = '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;

这是一个有点危险的浮点运算,但它可能会为你的目的工作。

难以置信,你只是顺便做了这个。非常感谢你!