甲骨间隔算术用于汇总行
我正在通过将其时间戳将其编写为集合块的询问。查询参数包括第一个聚合块的启动时间开始和一个正整数ociper
,这是几分钟内每个聚合块的长度。给定一个行的时间戳记row_stamp
,它比start
晚,我想计算其block_start
,以便block_start
- &lt ; =
row_stamp
<block_start
+期间
分钟和 block_start
=start
+(n *ofiper> ofiper> ofient> ofient
分钟分钟)n是一个非负整数,
很容易找到row_stamp- start
,这似乎是一个间隔。我认为我希望block_start
是start +(eride Minee) * floor((row_stamp- start -start)/(erige Minee)/(ercode mistion))
或row_stamp- mod(row_stamp-开始,周期分钟)
。我知道这些都不是确切的语法,但是我认为您看到了我要想要的算法。不幸的是,看起来floor
也不是mod
在一个间隔作为其第一个参数的效果很好。推荐将间隔变成数分钟的推荐方法是什么,然后在数学后将其重新转换回一个间隔?
我很抱歉没有提到我正在寻找每个聚合块中的行数。编辑以添加一个示例。
CREATE TABLE "DEV_JKNIGHT" ( "ROW_STAMP" TIMESTAMP (6) NOT NULL );
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:27:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:32:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:33:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 15:01:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 16:32:00');
假设查询参数是'2022-06-27 14:15:00'的开始时间和15分钟的时间。那么聚合块如下。第一个从指定的开始时间开始,并且持续时间持续时间。下一个块在第一个结束后立即开始并持续相同的长度。
- 14:15:00-14
- :30:00,6月27日14:30:00-14:45:00,6月27日
- 14:45:00-15:00:00,6月27日
- 15:00:00:00-15:15:00 15:00,6月27日
- ,依此类推,
如果我使用这些参数运行查询,那么我正在寻找这四行输出。
- Block Start ='2022-06-27 14:15:00',count =“ 1”
- Block start ='2022-06-27 14:30:00',count =“ 2”
- Block start ='2022-06-- 27 15:00:00',count =“ 1”
- 块start ='2022-06-27 16:30:00',count =“ 1”
输出的第一行表示有一个,只有一个,dev_jknight从14:15:00开始的聚合块中的行 - 即,该行在14:27:00。
第二行输出表明聚合块中有两个Dev_jknight行,该行从14:30:00开始 - 排在14:32和14:33。
由于第三个聚合块(14:45-15:00)中的DEV_JKNIGHT行零,因此没有输出行。
最后两行的输出表明,聚合块中有一个Dev_jknight行,该行从15:00开始,一个在16:30开始的块中。
在我澄清时,感谢您的耐心配合。
I'm writing a query to group rows by their timestamps into aggregation blocks. The query parameters include the start time start
of the first aggregation block and a positive integer period
which is the length of each and every aggregation block in minutes. Given a row's timestamp row_stamp
, which is later than start
, I want to calculate its block_start
such that
block_start
<=row_stamp
<block_start
+period
minutes, andblock_start
=start
+ (N *period
minutes) where N is a nonnegative integer
It's easy enough to find row_stamp - start
, which appears to be an interval. I figure I'll want block_start
to be either start + (period minutes) * FLOOR((row_stamp - start) / (period minutes))
or row_stamp - MOD(row_stamp - start, period minutes)
. I know neither of these is exact syntax, but I think you see the algorithms I'm going for. Unfortunately, it looks like neither FLOOR
nor MOD
works well with an interval as its first parameter. What's the recommended way to turn an interval into a number of minutes and then, after the math, turn it back to an interval again?
My apologies for not mentioning earlier that I'm looking for the number of rows in each aggregation block. Edited to add an example.
CREATE TABLE "DEV_JKNIGHT" ( "ROW_STAMP" TIMESTAMP (6) NOT NULL );
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:27:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:32:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 14:33:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 15:01:00');
insert into dev_jknight values (TIMESTAMP '2022-06-27 16:32:00');
Suppose the query parameters are a start time of '2022-06-27 14:15:00' and a period of 15 minutes. Then the aggregation blocks are as follows. The first begins at the specified start time and lasts for the period number of minutes. The next block starts immediately after the first one ends and lasts the same length.
- 14:15:00 - 14:30:00, June 27
- 14:30:00 - 14:45:00, June 27
- 14:45:00 - 15:00:00, June 27
- 15:00:00 - 15:15:00, June 27
- and so on
If I run the query with those parameters, then I'm looking for these four rows of output.
- Block start = '2022-06-27 14:15:00', count = "1"
- Block start = '2022-06-27 14:30:00', count = "2"
- Block start = '2022-06-27 15:00:00', count = "1"
- Block start = '2022-06-27 16:30:00', count = "1"
The first row of output indicates that there is one, and only one, dev_jknight row in the aggregation block which starts at 14:15:00 -- namely, the row at 14:27:00.
The second row of output indicates that there are two dev_jknight rows in the aggregation block which starts at 14:30:00 -- the rows at 14:32 and 14:33.
Because there are zero dev_jknight rows in the third aggregation block (14:45 - 15:00), there is no output row for it.
The last two rows of output indicate that there is one dev_jknight rows in the aggregation block which starts at 15:00 and one in the block which starts at 16:30.
Thank you for your patience while I clarified this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
提取
:输出:
将1分钟的间隔乘以分钟数:
或者,使用
numtodsinterval
函数:db&lt;&gt;在这里
Use
EXTRACT
:Which outputs:
Multiply a 1 minute interval by the number of minutes:
or, use the
NUMTODSINTERVAL
function:db<>fiddle here