-- 表结构
/*
id int,
strA varchar(50),
createDate datetime
*/-- 数据
/*
1   A1   2012-07-19 11:52:14
2   A2   2012-07-19 11:59:17
3   A3   2012-07-19 13:11:22
4   A4   2012-07-21 13:12:15
5   A5   2012-07-21 18:08:54
6   A6   2012-07-23 08:09:31
7   A7   2012-07-30 21:37:38
8   A8   2012-07-30 22:04:32
9   A9   2012-07-30 22:17:04
10  A10  2012-07-31 14:37:38
*/-- 要求生成如下格式:
/*
日期          访问次数
2012-07-19       3
2012-07-21       2
2012-07-23       1
2012-07-30       3
2012-07-31       1
*/

解决方案 »

  1.   


    select thisDate, count(*) from (
        select date(createDate) as thisDate from 表
    ) as T group by thisDate order by thisDate;
      

  2.   

    select left(createDate, 10) as '日期', count(id) as '访问次数'
    from 表
    group by left(createDate, 10)
      

  3.   

    select date(createDate),count(*)
    from tb
    group by date(createDate)
      

  4.   

    SELECT DATE(createDate),COUNT(*)
    FROM tb
    GROUP BY DATE(createDate);
      

  5.   

    SELECT DATE(createDate) as `日期`,COUNT(*) as `访问次数`
    FROM 表结构
    GROUP BY DATE(createDate);