【问题标题】:How to get the name of the month with year in a single statement in Postgres如何在 Postgres 的单个语句中获取带有年份的月份名称
【发布时间】:2021-07-01 08:48:53
【问题描述】:

目前我有一个名为月份和年份的列,如下图所示。

我可以知道如何在单个查询中获取月份名称和年份作为结果吗

【问题讨论】:

    标签: postgresql datetime


    【解决方案1】:

    你可以尝试下面的语句来生成类似上面的输出。

    SELECT (TO_CHAR(TO_DATE(CAST (month AS TEXT), 'MM'), 'Month') || ' ' || year) AS "expected_outcome";
    

    短月:

        SELECT (TO_CHAR(TO_DATE(CAST (month AS TEXT), 'MM'), 'Mon') || ' ' || year) AS "expected_outcome";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      相关资源
      最近更新 更多