How to get week start and end date string in PostgreSQL?

前端 未结 4 1403
野性不改
野性不改 2020-12-25 10:47

I am using PostgreSQL 8.3. I have a table like this:

id        regist_time        result
-----------------------------------
1     2012-07-0         


        
4条回答
  •  抹茶落季
    2020-12-25 11:38

    select date_trunc('week', regist_time)::date || ' - ' ||
           (date_trunc('week', regist_time) + '6 days') ::date as Week,
           sum(result) Total
    from YourTable
    group by date_trunc('week', regist_time)
    order by date_trunc('week', regist_time)
    

    See proof of concept at SQLFiddle: http://sqlfiddle.com/#!1/9e821/1

提交回复
热议问题