sql - aws Timestream:获取空间隔
问题描述
我想使用 aws timestream 来跟踪用户对我们 API 的请求。在第一步中,我只是将每个请求的用户 ID 存储到 API。对于图表,我想获取用户在特定时间间隔内的请求数。此 SQL 每隔 10 分钟从用户 2 获取最近两小时内的请求:
SELECT user_id, COUNT(user_id) AS n, bin(time, 10m) AS btime
FROM db_api.t_access
WHERE time > ago(2h) AND user_id IN ('2')
GROUP BY user_id, bin(time, 10m)
ORDER BY btime DESC
结果是:
2021-03-06 00:20:00.000000000 user_id:2 Count:1
2021-03-06 00:10:00.000000000 user_id:2 Count:4
2021-03-05 23:40:00.000000000 user_id:2 Count:2
没有请求的时间间隔不会返回,这里是 00:00 和 23:50。有没有办法在 SQL 中使用 Count = 0 来获得这个空间隔?还是我必须编写自己的代码才能从结果集中获取所有间隔(我使用 aws PHP API)?
解决方案
您可以使用:
interpolate_fill(timeseries, array[timestamp], double)
推荐阅读
- python - 将 HTML 文件从 Django 视图传递到 Django 模板
- javascript - 计算当前时间相对于日出和日落时间的百分比?
- sbt - 带有模糊版本错误的 Akka Testkit 错误
- javascript - 单击另一个div时如何隐藏div
- python - 使用字典字典中的 1 列创建 DataFrame
- python-3.x - 防鬼事件
- python - 我在第三次迭代中卡住的这些 while 循环做错了什么?
- python - 插入数据库,但它们是整数而不是字符串和前导零我想要消失
- pine-script - 关于 Pine-script 的问题:执行多行替代代码
- python - linux CAN协议最大速率