根据不同的列值的滤波行上的滤波行
我一直在尝试根据task_dts的值过滤带有代码
的一定值行。 本质上,我只需要行 per id ,其中task_dts
timestamp属于code_dts
当前 code> code 和code_dts
的 code
。
例如;对于代码
等于'z'的行,我只想要task_dts
在code> code_dts
的范围内的行,值'z '和价值'y'。 对于code
等于'y'的行,我只想要task_dts
在code> code_dts
for Value'的范围内的行。 y'and value x'等
桌子看起来如下:
rowID | ID | 代码 | code_dts | task_dts | 2022-02-02-01 |
---|---|---|---|---|---|
1 | A | z | 2022-02-01 10:17:08.403000 | : | 21:21: |
27.0000002 | 1 | 我的 | 10 -01 10:17:08.403000 | 2 | :21:31.000000 |
3 | A | Z | 2022-02-01 10:17 | 3 | 2022-02-02-01 12:41:41: |
4 | 2022-02-01 10 | 43.000000 | : 08.403000 11:12:13.270000 | 1 | 2022-02-01 10:21:21:27.000000 |
5 | A | Y | 2022-02-01 11:12:13.270000 | 3 | 2022-02-02-01 12:41:43.000000 |
6 | A | Y | 2022-02-02-01 11: 12:13.270000 | 8 | 2022-02-21 14:57:53.000000 |
7 | A | X | 2022-02-21 12:28:50.647000 | 6 | 2022-02-21 14:57:53.000000 |
8 | A | x | 2022-21 12:28: 50.647000 | 7 | 2022-02-21 14:57:54.000000 |
9 | b | h | 2022-04-05 13:44:16.030000 | 1 | 2022-04-05 14:03:56.570000 |
10 | b | h | 2022-04-05 13:44:16.030000 | 2 | 2022-04-05 14:03:56.570000 |
11 | B | I | 2022-04-06 13:44:16.030000 | 1 | 2022-04-04-05 14:03: |
56.570000 12 | B | J | 20222-2022-2022-04-07 13:44:16.030000 | 3 | 20222- 04-05 14:03:56.570000 |
输出看起来像:
ROWID | ID | ID | CODE_DTS | 任务 | task_dts |
---|---|---|---|---|---|
1 | A | Z | 2022-02-02-01 10:17:08.403000 | 1 | 2022-02-02-01 10:21:21:27.000000 |
2 | A | Z | 2022-2022-2022-2022-2022-2022-2022-2022-2022-2022-2022-2022-2022 A z 2022-2022-2022-2022-2022-2022-2022-2022-2022- 2022 A Z 2022-- 2022-2022-2022-2022-2022-2022-2022-2022-2022-2022-21:21:21:21:27.0000 02-01 10:17:08.403000 | 2 | 2022-02-01 10:21:31.000000 |
5 | a | y | 2022-02-01 11:12:13.270000 | 3 | 2022-02-01 12:41:43.000000 |
7 | a | x | 2022-02- 21 12:28:50.647000 | 6 | 2022-02-21 14:57:53.000000 |
8 | A | x | 2022-02-21 12:28: | 50.647000 7 | 2022-02-21 14:57:54.000000 |
10 | B | H | 2022-04-04-04-05 13 :44:16.030000 | 2 | :56.570000 |
B | I | 2022-04-06 | 44: | 16.030000 1 | 2022-04-04-04:03:03:03:56.570000 |
12 | 2022-04-05 14:03: 03 | 11 | 13 : :16.030000 | 3 | 2022-04-05 14:03:56.570000 |
我试图以合格而无益地解决此问题。帮助您将不胜感激
I've been trying to filter rows with a certain value for code
based on the values of task_dts.
Essentially I only want the rows per id where the task_dts
timestamp falls between the code_dts
timestamp of the current code
and the code_dts
of the following code
.
For example; for the rows where code
equals 'z', I only want the rows where the task_dts
is in the range of the code_dts
for value 'z' and value 'y'.
For the rows where the code
equals 'y', I only want the rows where the task_dts
is in the range of the code_dts
for value 'y' and value 'x' etc
My table looks the following:
rowid | id | code | code_dts | task | task_dts |
---|---|---|---|---|---|
1 | a | z | 2022-02-01 10:17:08.403000 | 1 | 2022-02-01 10:21:27.000000 |
2 | a | z | 2022-02-01 10:17:08.403000 | 2 | 2022-02-01 10:21:31.000000 |
3 | a | z | 2022-02-01 10:17:08.403000 | 3 | 2022-02-01 12:41:43.000000 |
4 | a | y | 2022-02-01 11:12:13.270000 | 1 | 2022-02-01 10:21:27.000000 |
5 | a | y | 2022-02-01 11:12:13.270000 | 3 | 2022-02-01 12:41:43.000000 |
6 | a | y | 2022-02-01 11:12:13.270000 | 8 | 2022-02-21 14:57:53.000000 |
7 | a | x | 2022-02-21 12:28:50.647000 | 6 | 2022-02-21 14:57:53.000000 |
8 | a | x | 2022-02-21 12:28:50.647000 | 7 | 2022-02-21 14:57:54.000000 |
9 | b | h | 2022-04-05 13:44:16.030000 | 1 | 2022-04-05 14:03:56.570000 |
10 | b | h | 2022-04-05 13:44:16.030000 | 2 | 2022-04-05 14:03:56.570000 |
11 | b | i | 2022-04-06 13:44:16.030000 | 1 | 2022-04-05 14:03:56.570000 |
12 | b | j | 2022-04-07 13:44:16.030000 | 3 | 2022-04-05 14:03:56.570000 |
The output would look like this:
rowid | id | code | code_dts | task | task_dts |
---|---|---|---|---|---|
1 | a | z | 2022-02-01 10:17:08.403000 | 1 | 2022-02-01 10:21:27.000000 |
2 | a | z | 2022-02-01 10:17:08.403000 | 2 | 2022-02-01 10:21:31.000000 |
5 | a | y | 2022-02-01 11:12:13.270000 | 3 | 2022-02-01 12:41:43.000000 |
7 | a | x | 2022-02-21 12:28:50.647000 | 6 | 2022-02-21 14:57:53.000000 |
8 | a | x | 2022-02-21 12:28:50.647000 | 7 | 2022-02-21 14:57:54.000000 |
10 | b | h | 2022-04-05 13:44:16.030000 | 2 | 2022-04-05 14:03:56.570000 |
11 | b | i | 2022-04-06 13:44:16.030000 | 1 | 2022-04-05 14:03:56.570000 |
12 | b | j | 2022-04-07 13:44:16.030000 | 3 | 2022-04-05 14:03:56.570000 |
I've tried to solve this with qualify without succes. help would be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用表格表达式来预测时间戳范围。然后,过滤很容易。
例如:
You can use a table expression to pre-compute the timestamp ranges. Then, filtering is easy.
For example:
阅读了Impaler的答案后,我终于理解了您的要求:-)
这是基于窗口功能的逻辑相同的:
很难分辨哪个会更好...
After reading The Impaler's answer I finally understood your requirements :-)
This is the same logic based on Window Functions:
Hard to tell which one will perfrom better...