select count(id),out_date
from out_bill
group by out_date
:2009-08-07    11个
2009-08-11    63个我想没有的天也显示为0怎么做?

解决方案 »

  1.   

    生成有所有日期的临时表,与工作表UNION OR 连接,再分组
      

  2.   

    需要另建一个日期表 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
      

  3.   

    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