【发布时间】:2012-06-08 02:00:05
【问题描述】:
我在 postgres 数据库中有一个时间戳字段。我想选择上个月内发生的所有日期。所以像 select * from table where timestamp > (current timestamp - 1 month) 之类的。
【问题讨论】:
标签: sql postgresql date select timestamp
我在 postgres 数据库中有一个时间戳字段。我想选择上个月内发生的所有日期。所以像 select * from table where timestamp > (current timestamp - 1 month) 之类的。
【问题讨论】:
标签: sql postgresql date select timestamp
select * from table where timestamp > now() - interval '1 month'
【讨论】:
timestamp 替换为 created_at)
准确地说:
SELECT *
FROM tbl
WHERE ts_col > now() - interval '1 month'
AND ts_col <= now();
【讨论】: