在第一个表里,每次用户登录就会增加一条信息:
id       uid         os                 time1          1            Android       201303041212122         2             Android       201303041212122          1            ios           20130305121212
需求是,统计这个表,得到以下结果并存入新表
id             uid           cishu    date1               1             1        201303042               2             1        20130304
3               1             1        20130305
即查一个uid在每一天出现的次数
请问这个sql语句,怎么实现,
以后这个还要求用存储过程来写,谢谢。
这个问题原来是这样http://zhidao.baidu.com/question/529658473.html
只按用户分组,现在还要按日期分组了。sql语句mysql存储sql

解决方案 »

  1.   

    select *,(select count(*) from tt where a.uid=uid and left(a.time,6)=left(time,6)) from aa a
      

  2.   

    select uid,date,count(*)
    from tb
    group by uid,time
      

  3.   

    select id,uid,count(id) as cishu,left(date,8)as date  from t1 group by left(date,8),uid order by left(date,8) asc;
      

  4.   

    select uid,left(time,8),count(*) 
    from 第一个表
    group by uid,left(time,8)
      

  5.   

    谢谢您的回答,可以运行;但假如用uid作为新表的字段,cishu作为值,按天划分可以实现吗?
    id             uid_1           uid_2    date1               1             2        201303042               1             0        20130305