Php 正在尝试查找订阅月底通知

Php 正在尝试查找订阅月底通知,php,mysql,sql,date,Php,Mysql,Sql,Date,嗨,我有这张桌子 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 我想要的是在截止日期前一个

嗨,我有这张桌子

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;
选择count(subend)作为count,curdate()
从状态为“活动”的俯冲
和(date_sub(subend,间隔1个月))>=curdate()
和(date_sub(subend,interval 1 month))试试这个:

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

另一种方法是使用:


您当前的查询有什么问题?您的查询有效吗?这会引起错误吗?你有什么问题吗?它没有给我正确的答案。比如给我看那些离他们的分包日期还有一个月的人。你真的需要在你的问题上投入更多的精力。“没有正确的答案”实际上什么都没说。如果它能给出“正确的答案”(不管是什么),你就不会在这里发帖了。请显示您获得的实际结果和期望的结果。在查询中,您的状态为“活动”,但表中没有状态字段。请把表格的所有字段都贴出来。哦,我明白你的意思了。我越来越深了。就这么简单。非常感谢你。
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
;