Sql 如何将时间列分组为5秒间隔,并使用Presto计算行数?
我用的是普雷斯托和齐柏林飞艇。有很多原始数据。 我必须总结这些数据 我想每5秒分组一次Sql 如何将时间列分组为5秒间隔,并使用Presto计算行数?,sql,apache-zeppelin,presto,Sql,Apache Zeppelin,Presto,我用的是普雷斯托和齐柏林飞艇。有很多原始数据。 我必须总结这些数据 我想每5秒分组一次 serviceType logType date ------------------------------------------------------ service1 log1 2017-10-24 23:00:23.206 service1 log1 2017-10-24 23:00:23.207 servi
serviceType logType date
------------------------------------------------------
service1 log1 2017-10-24 23:00:23.206
service1 log1 2017-10-24 23:00:23.207
service1 log1 2017-10-24 23:00:25.206
service2 log1 2017-10-24 23:00:24.206
service1 log2 2017-10-24 23:00:27.206
service1 log2 2017-10-24 23:00:29.302
那么结果呢
serviceType logType date cnt
--------------------------------------------------------------
service1 log1 2017-10-24 23:00:20 2
service2 log1 2017-10-24 23:00:20 1
service1 log1 2017-10-24 23:00:25 1
service1 log2 2017-10-24 23:00:25 2
首先,我必须将存储的数据迁移到新表中
其次,我必须分组数据并实时保存到新表中
编写sql脚本很难
请帮帮我
我必须使用python解释器吗?您可以
ts-间隔“1”秒*(秒(ts)%5)
presto> SELECT ts_rounded, count(*)
-> FROM (
-> SELECT date_trunc('second', ts) - interval '1' second * (second(ts) % 5) AS ts_rounded
-> FROM (VALUES timestamp '2017-10-24 23:01:20.206',
-> timestamp '2017-10-24 23:01:23.206',
-> timestamp '2017-10-24 23:01:23.207',
-> timestamp '2017-10-24 23:01:26.206') AS t(ts)
-> )
-> GROUP BY ts_rounded ORDER BY ts_rounded;
ts_rounded | _col1
-------------------------+-------
2017-10-24 23:01:20.000 | 3
2017-10-24 23:01:25.000 | 1
(2 rows)