比如我现在有一个表,字段如下
id ip dateid是自动编号
ip是访问本站的ip地址(可重复)
date是访问时间请问如何得出以下结果
访问最多的ip按访问次数排序
自动编号 ip地址         访问次数 
1       192.168.1.3    8
2       192.168.1.8    5
3       192.168.1.5    4
4       192.168.1.2    3
5       192.168.1.9    1

解决方案 »

  1.   

    select ip,count(ip) as times from tb
    order by times desc
    你编号查询出来就不是连续的了!没必要再查询出来了吧!
      

  2.   

    点快了..写错了:
    select  distinct ip,count(ip)   as   times   from   tb 
    group by ip
    order   by   times   desc 
      

  3.   

    select   ip,count(ip)   as   times   from   tb 
    order   by   times   desc 
    对头
      

  4.   


    select id as 自动编号,ip as ip地址,count(ip) as 访问次数 from t group by ip order by 访问次数
      

  5.   

    select ip,count(ip)as times from table group by ip order by times desc
      

  6.   

    select ip,sum(ip) from 表 group by ip order by sum(ip) DESC
      

  7.   

    select id as 自动编号,ip as ip地址,count(ip) as 访问次数 from t group by ip order by 访问次数这个是正解.
    肯定要分组的,不然count或sum都是全部计算了,
    csdn高人好多,学习ing
      

  8.   

    SELECT (SELECT COUNT(*) FROM 
    (SELECT ip,COUNT(*) cnt FROM tb GROUP BY ip) b
    WHERE ip!=a.ip AND cnt>=a.cnt
    ) 排名
    ip ip地址,cnt 访问次数
    FROM 
    (SELECT ip,COUNT(*) cnt FROM tb GROUP BY ip) a
      

  9.   

    少敲了一个逗号SELECT (SELECT COUNT(*) FROM 
    (SELECT ip,COUNT(*) cnt FROM tb GROUP BY ip) b
    WHERE ip!=a.ip AND cnt>=a.cnt
    ) 排名,
    ip ip地址,cnt 访问次数
    FROM 
    (SELECT ip,COUNT(*) cnt FROM tb GROUP BY ip) a另外,以上语句是不考滤某几个ip的count数相同的情况.
    若考滤这个情况,再按id比较即可,不写了.
      

  10.   

    很简单啊
    select   id   as   自动编号,ip   as   ip地址,count(ip)   as   访问次数   from   t   group   by   ip   order   by   访问次数