甲骨间隔算术用于汇总行

发布于 2025-02-11 01:04:53 字数 2107 浏览 0 评论 0原文

我正在通过将其时间戳将其编写为集合块的询问。查询参数包括第一个聚合块的启动时间开始和一个正整数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_startstart +(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, and
  • block_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老娘不死你永远是小三 2025-02-18 01:04:53

将一个间隔变成几分钟?

使用提取

SELECT   EXTRACT(DAY    FROM value) * 24 * 60
       + EXTRACT(HOUR   FROM value) * 60
       + EXTRACT(MINUTE FROM value)
       + EXTRACT(SECOND FROM value) / 60 AS minutes
FROM   (
  SELECT INTERVAL '1 12:34:56.789' DAY TO SECOND AS value
  FROM   DUAL
);

输出:

分钟
2194.94648333333333333333333333333333333333333333333

然后再次将其转回间隔?

将1分钟的间隔乘以分钟数:

SELECT INTERVAL '1' MINUTE * 2194.94648333333 AS interval_value
FROM   DUAL;

或者,使用numtodsinterval函数:

SELECT NUMTODSINTERVAL(2194.94648333333, 'MINUTE') AS interval_value FROM DUAL;
Interval_value
+000000001 12:34:56.789000000

db&lt;&gt;在这里

Turn an interval into a number of minutes?

Use EXTRACT:

SELECT   EXTRACT(DAY    FROM value) * 24 * 60
       + EXTRACT(HOUR   FROM value) * 60
       + EXTRACT(MINUTE FROM value)
       + EXTRACT(SECOND FROM value) / 60 AS minutes
FROM   (
  SELECT INTERVAL '1 12:34:56.789' DAY TO SECOND AS value
  FROM   DUAL
);

Which outputs:

MINUTES
2194.946483333333333333333333333333333333

and then turn it back to an interval again?

Multiply a 1 minute interval by the number of minutes:

SELECT INTERVAL '1' MINUTE * 2194.94648333333 AS interval_value
FROM   DUAL;

or, use the NUMTODSINTERVAL function:

SELECT NUMTODSINTERVAL(2194.94648333333, 'MINUTE') AS interval_value FROM DUAL;
INTERVAL_VALUE
+000000001 12:34:56.789000000

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文