【问题标题】:How to extract the year from a numeric string using Sql/Presto?如何使用 Sql/Presto 从数字字符串中提取年份?
【发布时间】:2021-05-06 18:24:45
【问题描述】:

您好,我正在通过 Presto 使用 SQL,我正在尝试从下面的数字字符串中提取年份以及如何对字符串进行分组,以便我可以按年而不是按月提取。该字符串不存储为日期,而是存储为数字。以下为 2019 年 1 月。

201901

【问题讨论】:

    标签: sql datetime extract presto trino


    【解决方案1】:

    除以 100:

    select floor(num / 100) as year
    

    注意:Presto 进行整数除法。所以如果“数字”值是一个整数,你可以使用:

    select num / 100 as year
    

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2019-12-21
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2021-04-14
      • 1970-01-01
      相关资源
      最近更新 更多