SQL - 两个字段更改之间的最大和最短时间
我有一个包含两列的 PL/SQL 表:log_date
(DATE) 和 value
(FLOAT)。数据非常细粒度,log_dates
之间的差异可能只有几毫秒。 值
随着时间的推移而变化。我想使用 SQL 查找 log_date
之间 value
增加所需的最大和最小时间量。
编辑:示例
log_date | value
-------------------
15:00 | 10
15:01 | 10
15:02 | 11
15:03 | 11
15:04 | 11
15:05 | 11
15:06 | 12
在 15:00 和 15:02 之间 value
增加,但在 15:03 到 15:06 之间也增加,这花费了更长的时间,所以我想要一个能够返回的查询(在本例中) “3 分钟”(作为日期或数字)- 值
增加所需的最长时间。
I have a PL/SQL table with two columns: log_date
(DATE) and value
(FLOAT). The data is very fine-grained, the difference between log_dates
could be a few milliseconds. The value
changes over time. I want to find, using SQL, the maximum and minimum amount of time between log_date
s it takes for value
to increase.
Edit: Example
log_date | value
-------------------
15:00 | 10
15:01 | 10
15:02 | 11
15:03 | 11
15:04 | 11
15:05 | 11
15:06 | 12
Between 15:00 and 15:02 value
increased BUT it also increased between 15:03 and 15:06 which took longer, and so I want a query that would return (in this case) '3 minutes' (as a DATE or a NUMBER) - the longest amount of time it took for value
to increase.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以用 T-SQL 给你答案,但我不确定你使用的是什么方言。说实话,这里首先想到的是循环(其他人可能有更好的方法!):
这样,您最终会得到一个包含所有差异的表,然后您可以查询该表。
华泰
I can give you an answer in T-SQL, but I'm not sure what dialect you're using. TBH, a loop here is the first thing that springs to mind (someone else may have a better way of doing it!):
This way, you end up with a table of all differences that you can then query.
HTH
您可以使用此查询查找特定值的最大和最小 log_date。但为此您必须指定该值。如果您想让查询更通用,您可能需要稍微修改一下查询
You can use this query to find the max and min log_date for a specific value. But for this you will have to specify the value. You might have to modify the query a little if you want to make it more generic
尝试如下操作:
并将其他值的 asc 更改为 desc。
[编辑]
我目前无法实际测试这一点,所以我不确定 max-min 是否有效,如果失败,您可以使用其他答案之一中发布的 datediff 函数作为替代方案。
[/编辑]
Try something like the following:
and change the asc to desc for the other value.
[edit]
I can't actually test this at the moment, so I'm not sure if the max-min will work, you can use the datediff function posted in one of the other answers as an alternative if this fails.
[/edit]