有这样的表结构
------------------------
ip         octet      port
12.1.1.1   120         21
1.15.56.5  45           80
12.1.1.1   450          80  
...怎么样统计每个IP地址的总octet数? 就是要得到这样的查询结果:
------------------------
ip         octet      port
12.1.1.1   570         21
1.15.56.5  45           80
...
如何用SQL语句实现?
谢谢!

解决方案 »

  1.   

    select ip,sum(octet),port
    from yourtable
    group by ip,port
      

  2.   

    select ip,sum(octet) as octet,port
    from yourtable
    group by ip,port
      

  3.   

    select ip,sum(octet) as octet
    from yourtable
    group by ip
      

  4.   

    ip         octet      port
    12.1.1.1   570         21
    1.15.56.5  45           80
    ...select a.ip,a.octet,b.port
    from (select ip,sum(octet) as octet
         from yourtable
         group by ip) a, yourtable b
    where a.ip=b.ip