表结构如下:
id,username,datetime
1   甲      2011-7-10
2   乙      2011-7-10
3   张      2011-7-11
4   王      2011-7-12
5   李      2011-7-15现想得到7-10号至7-12号结果如下:日期        总人数
2011-7-10    2  
2011-7-11    1  
2011-7-12    1  

解决方案 »

  1.   

    select datetime, count(1)
    from tb
    group by datetime
      

  2.   


    select convert(varchar(10),[datetime],120) date, count(1) cnt
    from tb
    group by convert(varchar(10),[datetime],120)
      

  3.   

    select datetime, count(1)
    from tb
    group by datetime
    where convert(varchar(10),[datetime],120) between '2011-07-10' and '2011-07-12'
      

  4.   


    select convert(varchar(10),[datetime],120) date, count(1) cnt
    from tb
    where convert(varchar(10),[datetime],120) between '2011-07-10' and '2011-07-12'
    group by convert(varchar(10),[datetime],120)
      

  5.   

    select
     convert(varchar(10),[datetime],120) as 日期, count(1) as 总人数
    from
     tb
    group by
     convert(varchar(10),[datetime],120