需要另建一个日期表 calendar (cdate date primary key) 然后INSERT所有的日期。select c.cdate,count(b.id) from calendar c left join out_bill b on c.cdate=b.out_date where cdate beetween date1 and date2 group by c.cdate
select a.out_date, Ifnull(count(b.id),0) from ( select date_add('2009-08-07',interval help_topic_id day) as out_date from mysql.help_topic where date_add('2009-08-07',interval help_topic_id day)<='2009-08-11' ) a left join out_bill b on a.out_date=b.out_date group by a.out_date
然后INSERT所有的日期。select c.cdate,count(b.id)
from calendar c left join out_bill b on c.cdate=b.out_date
where cdate beetween date1 and date2
group by c.cdate
a.out_date,
Ifnull(count(b.id),0)
from
(
select
date_add('2009-08-07',interval help_topic_id day) as out_date
from
mysql.help_topic
where
date_add('2009-08-07',interval help_topic_id day)<='2009-08-11'
) a
left join
out_bill b
on
a.out_date=b.out_date
group by
a.out_date