【问题标题】:Alternative for teradata functions in snowflakesnowflake 中 teradata 函数的替代方案
【发布时间】:2023-01-19 09:11:42
【问题描述】:

对于以下 teradata 函数,snowflake 中是否有任何替代函数?

DAYNUMBER_OF_CALENDAR(),
DayOccurrence_Of_Month(),
WeekNumber_Of_Calendar(),
MonthNumber_Of_Quarter(),
QuarterNumber_Of_Year(),

【问题讨论】:

  • 到目前为止建议的答案是不正确的。 Teradata 中的“...Number_of_Calendar”函数是业务日历范围内的序列值,例如对于“2023-01-18”,DayNumber_of_Calendar 返回 44943,WeekNumber_of_Calendar 返回 6420,而 DayOccurrence_Of_Month 返回 3(该月的第三个星期三)。

标签: snowflake-cloud-data-platform teradata-sql-assistant teradatasql


【解决方案1】:
DayOccurrence_Of_Month() -> EXTRACT(DAY FROM <date>)
WeekNumber_Of_Calendar() -> DATE_PART(week, <date>)
MonthNumber_Of_Quarter() -> DATE_PART(month, <date>)
QuarterNumber_Of_Year() -> DATE_PART(quarter, <date>)

【讨论】:

    【解决方案2】:

    你能试试这些功能吗?

    Treadata func -           snowflake func 
    DAYNUMBER_OF_CALENDAR() - DAY( <date_or_timestamp_expr> )
    DayOccurrence_Of_Month() - DAYOFMONTH( <date_or_timestamp_expr> )
    QuarterNumber_Of_Year() - QUARTER( <date_or_timestamp_expr> )
    WeekNumber_Of_Calendar() - WEEKOFYEAR( <date_or_timestamp_expr> )
    

    【讨论】:

      【解决方案3】:

      这是 DAYOCCURANCE_OF_MONTH() 的一种方式,希望有人能想出一种更优雅的方法。

      TRUNC(DATEDIFF(DAY,DATE_TRUNC('MONTH',CURRENT_DATE()),CURRENT_DATE())/7)

      【讨论】:

        猜你喜欢
        • 2023-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-08
        • 2012-01-25
        • 1970-01-01
        相关资源
        最近更新 更多