[英]How to get 15 minutes intervals from a datetime column in snowflake
我有一個名為 kyc_updated_at 的列(輸入日期時間,例如:2022-06-28 18:45:00.000 +0000)。 我想在我的最終輸出中將此列拆分為 15 分鍾的間隔。 就像是:
KYC_Updated_at | Avergae_decision_time | cumilative_average_decison_time |
---|---|---|
8-815 | 0.15 | 0.15 |
815-830 | 0.38 | 0.265 |
830-845 | 0.45 | 0.3266666667 |
845-9 | 0.63 | 0.4025 |
9-915 | 0.7 | 0.462 |
所以截斷是你想要的:
因此,使用這個多列 sql 來顯示答案的構建:
select column1 as original
,hour(column1) || minute(column1) as pre_parts
,hour(column1) || trunc(minute(column1)/15)*15 as post_parts
from values
('2022-06-28 18:46:00'::timestamp),
('2022-06-28 18:45:00'::timestamp),
('2022-06-28 18:44:00'::timestamp)
原來的 | PRE_PARTS | POST_PARTS |
---|---|---|
2022-06-28 18:46:00.000 | 1846年 | 1845年 |
2022-06-28 18:45:00.000 | 1845年 | 1845年 |
2022-06-28 18:44:00.000 | 1844年 | 1830 |
截斷完整日期:
select column1 as original
,hour(column1) || trunc(minute(column1)/15)*15 as pre_parts
,to_timestamp(trunc(date_part(epoch_second, column1)/(15*60))*(15*60)) as full_trunc
from values
('2022-06-28 18:46:00'::timestamp),
('2022-06-28 18:45:00'::timestamp),
('2022-06-28 18:44:00'::timestamp)
原來的 | PRE_PARTS | FULL_TRUNC |
---|---|---|
2022-06-28 18:46:00.000 | 1845年 | 2022-06-28 18:45:00.000 |
2022-06-28 18:45:00.000 | 1845年 | 2022-06-28 18:45:00.000 |
2022-06-28 18:44:00.000 | 1830 | 2022-06-28 18:30:00.000 |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.