我有一个postgres表,它有以下字段
start_date,工期
工期包含任意数目的月,因此要计算结束日期,请将持续时间中的月添加到开始日期。现在,我想使用postgres查询执行类似的操作。
SELECT *
FROM table
WHERE start_date > '2010-05-12'
AND (start_date + duration) < '2010-05-12'这是可能的吗?如何正确地使用语法呢?
我的邮件版本是PostgreSQL 8.1.22 on x86_64-redhat-linux-gnu,由GCC gcc (Linux) 4.1.2 20080704 (redhat 4.1.2-48)编写。
发布于 2011-05-06 09:37:53
尝试:
(start_date + (duration * '1 month'::INTERVAL)) < '2010-05-12'或
(start_date + (duration || ' month')::INTERVAL) < '2010-05-12'更多信息:
发布于 2011-05-06 09:32:10
您可能会发现本文很有用:PostgreSQL: month := interval '30 days';
还有这个链接:http://wiki.postgresql.org/wiki/Working_with_Dates_and_Times_in_PostgreSQL,更具体地说,称为“使用日期时间、日期和间隔值”的部分。
https://stackoverflow.com/questions/5909363
复制相似问题