【发布时间】:2017-03-20 16:34:14
【问题描述】:
我查看了有关 postgreSQL 中时间元素的帖子,但到目前为止他们还没有为我点击。我想得到Last Year to Date,在这种情况下是 01/01/2016 到 03/20/2016 和Last Year Month to Date,在这种情况下是 03/01/2016 到 03/20/2016。
Get last 12 months data from Db with year in Postgres
get last three month records from table
select actual_sale_date from allsalesdata
where actual_sale_date > date_trunc('year', current_date)
提供 2017 年年初至今
select actual_sale_date from allsalesdata
where actual_sale_date > date_trunc('month', current_date)
提供 2017 年的月初至今
select actual_sale_date from allsalesdata
where actual_sale_date >= date_trunc('year', now() - interval '1 year')
and actual_sale_date < date_trunc('year',now())
提供去年 01/01 ----> 12/31 数据。
我可以在上面的 sn-ps 中添加什么,它可以为我提供去年至今和去年当月至今的数据。请提供帮助。
【问题讨论】:
标签: sql postgresql