如何在 PostgreSQL 中 select 指定日期?

How to select specific dates in PostgreSQL?

我的table:

create table example
(
        code           varchar(7),
        date           date,
CONSTRAINT pk_date PRIMARY KEY (code)
);

日期:

insert into example(code, date) 
values('001','2016/05/12');
insert into example(code, date) 
values('002','2016/04/11');
insert into example(code, date) 
values('003','2017/02/03');

我的问题:如何 select 以前的日期从今天算起六个月?

在 MySQL 中我可以使用 PERIOD_DIFF,但是,在 PostgreSQL 中?

你可以试试INTERVAL指令:

SELECT date
FROM example
WHERE date < CURRENT_DATE + INTERVAL '6 months'
AND date > CURRENT_DATE;

您将获得从今天到六个月的日期。