表结构如下
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 tt
    group by time,sip,dip,port
    order by 5 desc
    limit 20;
      

  2.   

    发重了 我晕顺便请假下又遇到的问题:如何将sql语句的输出定向到一个表里啊?
      

  3.   

    insert into tt
    select * from tt1
    假设结构一致
      

  4.   

    select * into syn_count from (select srcip,dstip,dstport,count(*) from syn
    group by srcip,dstip,dstport);我这么搞了下 出错了
    1327 - Undeclared variable: syn_count
      

  5.   

    create table syn_count as select srcip,dstip,dstport,count(*) from syn
    group by srcip,dstip,dstport