mysql5.0以上版本
大概是查询库里每天有多少人消费过结构大致如下ID     UserID     time
1      a          2013-5-5
2      b          2013-5-5
3      c          2013-5-10
4      a          2013-5-6
5      b          2013-5-10
6      c          2013-5-10
7      d          2013-5-11
8      a          2013-5-11
9      c          2013-5-12
10     d          2013-5-10查询后结果如下
2013-5-5   2
2013-5-6   1
2013-5-10  3
2013-5-11  2

解决方案 »

  1.   

    select t.time,count(t.id) from table t group by t.time
      

  2.   

    select `time`,count(distinct id) from tt group by `time`
      

  3.   

    select `time`,count(distinct UserID) 
    from 结构大致如下
    group by `time`
      

  4.   

    SELECT time,COUNT(primary key) FROM table GROUP BY time 
      

  5.   

    select time,count(id) from table group by time 
      

  6.   

    select `time`,count(distinct userid) from tbname group by `time`
      

  7.   


    可能是我表述不清吧, 不是要一个group by语句拿5-10为例如果单纯group by的话 5-10应该是4条信息 (3,5,6,10),但是因为3和6都是c,所以最后的答案5-10是3,不是4,因为分别出现了b,c,d,所以两次c只算1次
      

  8.   

    select time,count(time)from table_name group by time