【问题标题】:How to merge the dates into one column?如何将日期合并为一列?
【发布时间】:2021-10-26 12:01:36
【问题描述】:

我在单独的列中有年、月、日,我想将它们全部合并到雪花中的一列

【问题讨论】:

  • 作为显示输出,还是放入新的数据库列?
  • 是的,作为显示输出
  • concat

标签: sql database snowflake-cloud-data-platform datagrip


【解决方案1】:

您应该使用 DATE_FROM_PARTS 函数:

select date_from_parts(1977, 8, 7);

参考:DATE_FROM_PARTS

【讨论】:

    【解决方案2】:
    select year||'-'||month||'-'||day from table
    

    其中年、月和日是对应数据的列名。

    【讨论】:

      【解决方案3】:

      创建一个字符串表达式,然后使用 To_Date 函数。 例如:

      set (day, month, year) = ('26', '10', '2021');
      set strDate = concat(year, '-', month, '-', day);
      select to_date(strDate)
      

      【讨论】:

        猜你喜欢
        • 2021-12-16
        • 1970-01-01
        • 2012-08-19
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        • 2015-06-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多