如何获取 MIN 时间戳和 MAX 时间戳之间的时间差
我正在努力获得 MAX &特定时间范围的 MIN 时间戳。正如你在这里看到的:
我将使用 mysql 或 pl/sql
是否可以获得它?
例子:
Black block: 11/2/2022 05:45:28 ~ 11/2/2022 06:02:58
Red block: 13/2/2022 05:34:09 ~ 13/2/2022 06:32:44
Yellow block: 13/2/2022 10:28:06 ~ 13/2/2022 10:40:35
I'm trying to get the MAX & MIN Timestamp for the certain time frame. As you can see here:
I will use mysql or pl/sql
Is it possible to get it?
Example:
Black block: 11/2/2022 05:45:28 ~ 11/2/2022 06:02:58
Red block: 13/2/2022 05:34:09 ~ 13/2/2022 06:32:44
Yellow block: 13/2/2022 10:28:06 ~ 13/2/2022 10:40:35
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是:有可能得到它吗?
当然可以。我已经完成了,问题得到解答了吗?
好的,关于如何... :P
注意:
假设每个组以 Y 开头,以下一个 Y 之前的记录结束,并且按没有间隙的计数列排序。
不是一个完整的解决方案,但确实提供了足够的示例来构建。这解决了您的分组问题并获得了最小值/最大值,但它并没有使用您的所有列/数据来执行此操作,而且我实际上并没有减去它们......但它确实给出了您的“示例”结果。
我作弊并简单地使用#而不是实际的时间戳,因为我很懒并且不想设置数据。
使用示例数据创建 CTE
创建 STEP1 CTE,它创建了一列数据,根据列表中的下一个“Y”定义每个块/组,我将其称为“NextMinCount”,更恰当地命名为“MyGrouping”
然后,一旦我们有了块/分组栏
我们使用查询来获取每个组内的最小值/最大值
样本数据: DEMO DB FIDDLE UK
假设组以 Y 开头并以下一个 Y 之前的行结束假设按计数列排序,没有间隙。
给我们:
上面定义分组的核心是这个内联选择:
它只是识别最低的“Count”,即大于当前 count 的“Y”。从而定义组的范围。然后我们减去 1 以获得 Y 之前的行。我们使用合并来处理最后一个分组,该分组不会有下一个 Y 值,否则将是 NULL 名称;我们得到了第 1 步描述的第 1 步结果
第 1 步给出了我们:
最终查询给出了
WHERE nextMinCount 等于您的数据块,如第 1 步结果所示。
我相信这就是你所追求的。
The question is: Is it possible to get it?
Sure it is. I'm done here right Question answered?
Ok as to How... :P
NOTES:
Assumes each group begins with a Y and ends with the record prior to next Y and that is sorted by count column which has no gaps.
Not a complete solution but does provide a sufficient example to build from. This solves your Grouping problem and obtains the min/max but it doesn't do it using all your columns/data and I don't actually subtract them... but it does give your "Example" results.
I cheated and simply used #'s instead of actual timestmaps because I'm lazy and didn't want to setup the data.
Create CTE with sample data
Create STEP1 CTE which created a column of data which defines each Block/Group based on the next "Y" in your list I called it "NextMinCount" it would be more aptly named "MyGrouping"
Then once we have the block/group column
We use a query to get min/max within each group
SAMPLE DATA: DEMO DB FIDDLE UK
Assumes the groups begin with a Y and end with row prior to next Y assuming sorted by counts column with no gaps.
Giving us:
The heart of the above which defines the grouping is this inline select:
It simply identifies the lowest "Count" that is a "Y" that is greater than the current count . Thus defining the range for the group. We then subtract 1 to get the row prior to the Y. we use the coalesce to handle the last grouping which would not have a next Y value and would otherwise be NULL name; and we get the Step1 Results depicted for STEP 1
STEP 1 gives us:
The final query gives us
WHERE the nextMinCount equates to your blocks of data as the Step1 results show.
Which, I believe, is what you're after.