数据是这样的
code      event                  source
0001      192.168.0.5|wap|xx     xx
0001      192.168.0.3|web|xx     xx
0001      192.168.0.3|web|xx     xx
0001      192.168.25.26|xx|xx    xxevent字段的第一个“|”前面代表ip 我想按ip分组 请问如何写这样的sql语句

解决方案 »

  1.   

    希望地道的结果是
    0001      192.168.0.5    xx
    0001      192.168.0.3    xx
    0001      192.168.25.26    xx或
    0001      192.168.0.5|wap|xx     xx
    0001      192.168.0.3|web|xx     xx
    0001      192.168.25.26|xx|xx    xx
    都可以
      

  2.   

    select 
        t.ip,count(t.ip) as cnt 
    from 
        (select left(event,charindex('|',event)-1) as ip, from 表) t 
    group by 
        t.ip
      

  3.   

    select distinct code,left(event,charindex('|',event)-1) as ip,source from 表
      

  4.   

    select distinct * from  表第2个..如楼上的..慢了只有删了~