How do you select a date range in postgres?

你。 提交于 2019-12-30 07:20:10

问题


I have a timestamp field in a postgres database. I would like to select all dates that have happened within the last month. So something like select * from table where timestamp > (current timestamp - 1 month).


回答1:


select * from table where timestamp > now() - interval '1 month'



回答2:


To be precise:

SELECT *
FROM   tbl
WHERE  ts_col >  now() - interval '1 month'
AND    ts_col <= now();


来源:https://stackoverflow.com/questions/10942219/how-do-you-select-a-date-range-in-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!