【问题标题】:SQL Presto - How to convert dates into quarter/year format?SQL Presto - 如何将日期转换为季度/年格式?
【发布时间】:2023-01-22 23:41:26
【问题描述】:

我有一个日期需要在 SQL Presto 中汇总为季度/年度格式。请帮忙。谢谢!

【问题讨论】:

    标签: sql date format presto


    【解决方案1】:

    Documentation 是你的朋友 - 使用对应单位的date_trunc,或extraction functionsyearquarter):

    select date_trunc('quarter', now())
        , date_trunc('year', now()) 
        , quarter(now())
        , year(now())
    

    示例输出:

    _col0 _col1 _col2 _col3
    2022-07-01 00:00:00.000 UTC 2022-01-01 00:00:00.000 UTC 3 2022

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 2017-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多