snowflake中的start_time和末端之间的分时持续时间
我有一个具有以下格式的表。
user_id | start_time | end_time |
---|---|---|
aaa001 | 2020-04-04 09:09:04:27.000 | 2020-04-04 09:09:08:34.000, |
我需要通过添加一个分钟的插槽作为新列,以使每一分钟以我的新列来划分start_time和end_time之间的持续时间有一个独特的行。 The result I want to see like this:
USER_ID | START_TIME | END_TIME | MINUTE_SLOT |
---|---|---|---|
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:05:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:06:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:07:27.000 |
AAA001 | 2020-04-04 09:04 :27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:08:27.000 |
AAA001 | 2020-04-04 09:04:04:27.000 | 2020-04-04-04 09:08:54.000 | 2020-04-04-04-09:09:09:27.000 |
如果有人可以告诉我这是可能的,并且如何在雪花中做到这一点,这将不胜感激,谢谢!
I have a table with following format.
USER_ID | START_TIME | END_TIME |
---|---|---|
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:34.000 |
I need to split the duration between START_TIME and END_TIME by adding a one minute slots as a new column such that for each minute i have a unique row. The result I want to see like this:
USER_ID | START_TIME | END_TIME | MINUTE_SLOT |
---|---|---|---|
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:05:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:06:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:07:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:08:27.000 |
AAA001 | 2020-04-04 09:04:27.000 | 2020-04-04 09:08:54.000 | 2020-04-04 09:09:27.000 |
If anyone can tell me is this possible and how to do this in snowflake, that would be much appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下数据 -
第一种方法,如@Dave共享的一种方法,并具有限制子句(使用大生成器值) -
或者,由于限制了给出恒定值,以获取虚拟行并避免额外的行生成> Generator 子句。
两者都给出以下输出
With following data -
First approach, as the one shared by @Dave, with qualify clause to limit (use large generator value) -
Or, another one to get dummy rows and avoiding extra row generation due to limitation of giving constant value in
generator
clause.Both giving following output -
假设您想在start_time和end_time之间保持微小的插槽,并假设end_time -start_time< = 24小时:
基于一个想法,请 this”> this答案
Assuming you want to keep the minute slots between the start_time and end_time and assuming that the end_time - start_time <= 24 hours:
Based on an idea at this answer