查询结果中缺少今天的日期

时间:2014-09-10 07:42:05

标签: mysql sql mysql-workbench

我有一个方案从表中获取一些数据并按日期顺序显示它。它必须只显示10条记录,即今天日期前4天和今天日期后5天。 每件事都是从下面的查询开始工作,但我的结果中缺少当前日期

select fr.startDate,sum(fr.completed_visit) as completed_visit,sum(fr.canceled_visit) as canceled_visit,sum(fr.Failed_visit) as Failed_visit,    sum(fr.buyer_visit) as buyer_visit,sum(fr.buyerre_visit) as buyerre_visit,sum(fr.visit_sheduled) as visit_sheduled, sum(fr.visit_conferm) as visit_conferm from (select  start_date as startDate,timecreated ,DATE_FORMAT(timecreated,'%d-%b-%Y') as timeformat,
case when (visit_status='Completed') then 1 else 0 end completed_visit,   
case when (visit_status='Cancelled') then 1 else 0 end canceled_visit,
case when (visit_status='Cancelled/Failed') then 1 else 0 end    Failed_visit,
case when (visit_purpose='BuyerVisit') then 1 else 0 end buyer_visit,
case when (visit_purpose='BuyerReVisit') then 1 else 0 end buyerre_visit,
case when (confirm_status='0') then 1 else 0 end visit_sheduled,
case when (confirm_status='1') then 1 else 0 end visit_conferm 
from mg_visit_listing  order by startDate desc) fr
where  fr.startDate <=CurrentDate+5 group by fr.startDate order by fr.startDate desc  ;

我没有获取超过CurrentDate + 5但我的结果中缺少当前日期的值

1 个答案:

答案 0 :(得分:0)

您没有定义CurrentDate,还是您之前定义的var?。

比较日期时,您应使用date_adddate_diff

此外,更详细的解释不会受到影响(类似于创建表和一些初始插入)。