PLSQL-满足条件时测量持续时间
假设如下表所示:
time name availability
10:00 A 100
10:05 A 0
10:10 A 0
10:15 A 0
10:20 A 0
10:25 A 0
10:30 A 100
10:35 A 0
10:40 A 0
10:45 A 100
10:50 A 100
10:55 A 0
11:00 A 100
11:05 A 0
我想计算可用性等于零的每个事件的持续时间,这不仅意味着“0”的计数,还意味着下一个值再次变为之前第一个零和最后一个零之间的持续时间是多少100.
例如,在我的表中,我有 3 对事件 (up=100,down=0,up),其中第一个持续 25 分钟 (10:05-10:25),第二个持续 10 分钟,第三个持续 5 分钟。最后一个零不是 up-down-up 事件的一部分!
Assume a table as shown below:
time name availability
10:00 A 100
10:05 A 0
10:10 A 0
10:15 A 0
10:20 A 0
10:25 A 0
10:30 A 100
10:35 A 0
10:40 A 0
10:45 A 100
10:50 A 100
10:55 A 0
11:00 A 100
11:05 A 0
I want to calculate the duration of each event where the availability equals zero, meaning not just the count of "0" BUT what was the duration between the first zero and the last zero before the next value becomes again 100.
For example, in my table, I have 3 pair events (up=100,down=0,up) where the first lasts 25min (10:05-10:25), the second 10min and the third 5min. The last zero is not part of an up-down-up event!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LAG功能可以帮助您:
Oracle LAG 函数
The LAG function can help you:
Oracle LAG function
这并不能用原始之美来回答,至少据我所知。
不过,实现起来并不难。不过,您必须与分析函数成为朋友。在这种情况下:滞后和超前。
如果这是您想要得到的(我确信您可以自己计算差异,有趣的部分是获取范围),然后查看下面的查询:
This isn't going to be answered with something of pristine beauty, at least not to my knowledge.
It isn't that hard to accomplish, though. You have to become friends with analytic functions, though. in this case: Lag and Lead.
If this is what you want to get (I am positive you can calculate the difference yourself, the interesting part is to get the ranges), then check out the query below: