表结构
pid      date
1       2011-07-01
1       2011-06-30
1       2011-06-29
2       2011-06-29
2       2011-06-08
每天登陆只记录一次,一天内不会重复
现在需求是找出每周/月登陆大于3的总人数,请问该如何写,在线等了!

解决方案 »

  1.   

    统计每星期:
    select count(*)
    from (select pid,count(*) cnt from tablename group by pid,datepart(week,date)) a
    where a.cnt>3
      

  2.   


    select count(*)
    from (
           select pid,count(*) cnt 
           from tablename group by pid,datepart(week,date)
           where date>=date1 and date<=date2
         ) a
    where a.cnt>3
      

  3.   

    对不起,我写的是MS SQL的