表结构如下
time                    sip             dip             port2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173
2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173
2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690
2012-04-20 14:50:41 192.168.16.1 192.168.12.117 0
2012-04-20 14:50:41 139.86.96.146 192.168.120.189 23690
2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173
想要将sip、dip、port三项都相同的按 重复的次数从高到底排序 输出top20结果应该是这样 2012-04-20 14:50:41 192.168.12.117 192.168.1.100 1173 3次
2012-04-20 14:50:41 188.222.61.224 192.168.120.189 23690   2次
2012-04-20 14:50:41 192.168.16.1 192.168.12.117 0       1次如何用mysql实现,请大牛指点下?

解决方案 »

  1.   

    select  time sip dip port,count(*) from tb
    group by time sip dip port
    order by 2 desc
    limit 20;
      

  2.   

    不行啊,报错1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dstip dstport,count(*) from syn
    group by time srcip dstip dstport
      

  3.   

    select  time,sip,dip,port,count(*) from tt
    group by time,sip,dip,port
    order by 5 desc
    limit 20;