我有一个下面的表项目。
id title created_at claim_window 1 Project One 2012-05-08 13:50:09.924437 5 2 Project Two 2012-06-01 13:50:09.924437 10
A)我想找到计算期限的最后期限= created_at claim_window(天数)。
像下面的东西。
id title created_at claim_window deadline 1 Project One 2012-05-08 13:50:09.924437 5 2012-05-13 13:50:09.924437 2 Project Two 2012-06-01 13:50:09.924437 10 2012-06-11 13:50:09.924437
B]我还想找到那些截止日期已过的项目
id title created_at claim_window deadline 1 Project One 2012-05-08 13:50:09.924437 5 2012-05-13 13:50:09.924437
我尝试像下面的东西。
SELECT * FROM "projects" WHERE (DATE_PART('day',now()- created_at) >= (claim_window+1))
但由于某种原因,它不工作。
这将给你的最后期限:
select id,title,created_at + interval '1' day * claim_window as deadline from projects
要获得截止日期已过的所有项目,请使用:
select * from ( select id,created_at + interval '1' day * claim_window as deadline from projects ) t where localtimestamp at time zone 'UTC' > deadline