PostgreSQL - GROUP BY timestamp values?

后端 未结 2 1432
清酒与你
清酒与你 2021-02-18 20:15

I\'ve got a table with purchase orders stored in it. Each row has a timestamp indicating when the order was placed. I\'d like to be able to create a report indicating the numb

2条回答
  •  花落未央
    2021-02-18 21:07

    This does the trick without the date_trunc function (easier to read).

    // 2014
    select created_on::DATE from users group by created_on::DATE
    
    // updated September 2018 (thanks to @wegry)
    select created_on::DATE as co from users group by co
    

    What we're doing here is casting the original value into a DATE rendering the time data in this value inconsequential.

提交回复
热议问题