当sqlite中完全显示出野外值时,我将如何确定野外值出现的速率?
我有一个巨大的数据集。每个记录上都有一个时间戳(以字符串格式)。我正在尝试确定特定字段是一个特定值的次数。以一种更具体的方式:
+---------------------+-------+
| TimeStamp | Value |
+---------------------+-------+
| 2022-01-01 00:00:00 | A | A shows up 3 times in the first hour
| 2022-01-01 00:00:01 | B |
| 2022-01-01 00:00:05 | A |
| 2022-01-01 00:00:09 | A |
| 2022-01-01 05:00:01 | A | A shows up 2 times in the sixth hour
| 2022-01-01 05:00:02 | A |
+---------------------+-------+
我想看看一个小时内a
平均每小时出现多少次,不包括根本没有出现的时间。在这种情况下,5/2 =>每小时2.5次。 SQL是否可以做到这一点,还是我必须编写一个外部脚本来执行此操作?
I have a huge data set. Each record has a timestamp on it (in string format). I'm trying to determine how many times a particular field is a particular value. In a more concrete fashion:
+---------------------+-------+
| TimeStamp | Value |
+---------------------+-------+
| 2022-01-01 00:00:00 | A | A shows up 3 times in the first hour
| 2022-01-01 00:00:01 | B |
| 2022-01-01 00:00:05 | A |
| 2022-01-01 00:00:09 | A |
| 2022-01-01 05:00:01 | A | A shows up 2 times in the sixth hour
| 2022-01-01 05:00:02 | A |
+---------------------+-------+
I'd like to see how many times in an hour that A
shows up on average hourly excluding the time that it doesn't show up at all. In this case 5/2 => 2.5 times per hour. Is this even possible with SQL or will I have to write an external script to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要2个聚合级别:
或,使用
avg()
窗口函数:如果您想要所有
value
s:或:
请参阅 demo 。
。
You need 2 levels of aggregation:
or, with
AVG()
window function:If you want results for all
Value
s:or:
See the demo.