0

嗨,我有这个 mysql 表

id    amount     substart  years   subend

1     200       2012-01-10   1    2013-01-09 
2     250       2012-02-15   2    2014-02-14 
3     100       2012-02-11   1    2013-02-10 
4     260       2012-03-22   3    2015-03-21 

我想要的是在结束日期前一个月发出通知。当前查询是:

select  count(subend) as count,curdate() 
from subdur  where  status='active' 
and (date_sub(subend,interval 1 month))>=curdate() 
and (date_sub(subend,interval 1 month))<date_add(curdate(),interval 1 month) 
order by subend;

该查询没有给我正确的答案。

提前致谢

4

2 回答 2

0

试试这个::

select  
count(subend) as count,
curdate() 
from subdur  
where  status='active' and 
subend BETWEEN (date_sub(curdate(),interval 1 month)) and curdate() 
order by subend
于 2013-02-02T08:49:43.817 回答
0

另一种方法是使用date_diff

select count(subend) as count, curdate() 
from subdur  
where  status='active' 
and date_diff(subend, curdate()) = 30 // >= 30 days or more, = 30 days exact
order by subend
;
于 2013-02-02T09:05:48.383 回答