如何在 Snowflake 中获取周 ID
How to get week id in Snowflake
我想获取 Snowflake 中当前日期的周 ID
我尝试了以下查询。
SELECT to_number(to_char(to_date(current_date),'w')) from dual
这不起作用,
错误:数字:无法识别值 w
如何解决问题
谢谢
使用 WEEKOFYEAR or WEEKISO should be enough. You will want to read the how it week is defined,以确保它满足您的需求。
SELECT
current_date() AS a,
WEEKOFYEAR( a ),
WEEKISO( a )
;
给出:
A
WEEKOFYEAR( A )
WEEKISO( A )
2022-02-23
8
8
我想获取 Snowflake 中当前日期的周 ID
我尝试了以下查询。
SELECT to_number(to_char(to_date(current_date),'w')) from dual
这不起作用, 错误:数字:无法识别值 w 如何解决问题
谢谢
使用 WEEKOFYEAR or WEEKISO should be enough. You will want to read the how it week is defined,以确保它满足您的需求。
SELECT
current_date() AS a,
WEEKOFYEAR( a ),
WEEKISO( a )
;
给出:
A | WEEKOFYEAR( A ) | WEEKISO( A ) |
---|---|---|
2022-02-23 | 8 | 8 |