【问题标题】:SQL query to retrieve SUM in various DATE ranges based on timestamp with timezoneSQL 查询根据带时区的时间戳检索各种 DATE 范围内的 SUM
【发布时间】:2016-07-09 02:25:35
【问题描述】:

嗨,我有同样的问题 - SQL query to retrieve SUM in various DATE ranges - 除了没有日期,我有时间戳,当我尝试做 year(created)(创建的是时间戳)时,我得到一个错误:

函数年份(带时区的时间戳)不存在

总之,我试图获得与上面粘贴的链接中的请求相同的输出(按月列出的总和),但年和月函数似乎不适用于带有时区的时间戳.任何帮助将非常感激。谢谢!

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    试试这样的

     SELECT SUM(totalprice), date_part('year', your_time_stamp_column),
     date_part('month', your_time_stamp_column) 
    
    from sales
    group by date_part('year', your_time_stamp_column), 
    date_part('month', your_time_stamp_column)
    

    https://www.postgresql.org/docs/current/static/functions-datetime.html

    【讨论】:

      猜你喜欢
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 2014-05-07
      • 1970-01-01
      相关资源
      最近更新 更多