想统计登录记录里面的各个IP登录次数,并且按登录次数排序表 aa.id   a.ip           a.logintime
1      152.1.3         ........
2      117.88.2.116    ........
3      127.0.0.1       ........
4      127.0.0.1       ........
5      117.88.2.116    ........
6      127.0.0.1       ........想要的结果ip               登录次数
127.0.0.1        3
117.88.2.116     2
152.1.3          1请高手赐教,非常感谢。

解决方案 »

  1.   


    select ip,count(*) as cnt
    from a
    group by ip
    order by cnt desc
      

  2.   

    select ip,count(*) as 登入次数 from a group by(ip)
      

  3.   

    实在实在不好意思啊,我刚刚套用各位给我的语句时确实是好用的,但是我发现我提问的问题中少了一个条件,实在不好意思啊,能帮我看看如果再加上个最后登录时间语句应该怎么写吗?
    就是想要下面这样的ip            登录次数   最后登录时间
    127.0.0.1     3         2011-11-2 8:30 
    117.88.2.116  2         。。
    152.1.3       1         。。就是在原有基础上把每个IP的最后登录时间给取出来,非常感谢!这个属于我的疏忽,不管有没有回答我都会尽快结贴给分的,谢谢!
      

  4.   

    select ip,count(*),min(logintime) as cnt
    from a
    group by ip
    order by cnt desc
      

  5.   

    最后登录,是max...
    select ip,count(*),max(logintime) as cnt
    from a
    group by ip
    order by cnt desc
      

  6.   

    靠,今天怎么总错!
    select ip,count(*) as cnt,min(logintime) as lastlogin
    from a
    group by ip
    order by cnt desc
      

  7.   


    select ip,登录次数=count(*),最后登录时间=max(logintime) from a group by ip
      

  8.   

    今天很悲催,上面出好多错,复制人家的来改,不是件好事,还是得自己写哪!
    准确的是:
    select ip,count(*) as cnt,max(logintime) as lastlogin
    from a
    group by ip
    order by 2 desc
      

  9.   

    select
     ip,count(1) as cnt,min(logintime) as lastlogin
    from
     a
    group by
     ip
    order by
     cnt desc