called_station_id 字段 查询出结果 0×××××××× 和 00××××××××(首数字相同 尾数和位数不一定)需要将0……和00……分组并求和 怎么处理?

解决方案 »

  1.   

    select sum(value)
    from tb
    group by left(col,2)
      

  2.   

    ...........
    group by left(called_station_id  , 1 )union all ........
    group by left(called_station_id  , 2)
      

  3.   

    select len(replace(called_station_id,'0',''))
    from ta
    group by len(replace(called_station_id,'0',''))
      

  4.   

    按这个分组:len(replace(called_station_id,'0',''))
      

  5.   

    declare @t table(col varchar(10))
    insert @t select '0AAAAAAAAA'
    insert @t select '0AAAAAAAAA'
    insert @t select '00AAAAAAAA'
    insert @t select '00AAAAAAAA'
    insert @t select '00AAAAAAAA'
    insert @t select '00AAAAAAAA'
    insert @t select '0000AAAAAA'
    insert @t select '0000AAAAAA'
    select len(replace(col,'0','')),col,count(1) as cnt
    from @t
    group by len(replace(col,'0','')),col/*
                col        cnt         
    ----------- ---------- ----------- 
    6           0000AAAAAA 2
    8           00AAAAAAAA 4
    9           0AAAAAAAAA 2(所影响的行数为 3 行)*/
      

  6.   

    declare @t table(col varchar(10)) 
    insert @t select '0AAAAAAAAA' 
    insert @t select '0AAAAAAAAA' 
    insert @t select '00AAAAAAAA' 
    insert @t select '00AAAAAAAA' 
    insert @t select '00AAAAAAAA' 
    insert @t select '00AAAAAAAA' 
    insert @t select '0000AAAAAA' 
    insert @t select '0000AAAAAA' 
    select len(replace(col,'0','')),col,count(1) as cnt 
    from @t 
    group by len(replace(col,'0','')),col /* 
                col        cnt          
    ----------- ---------- -----------  
    6           0000AAAAAA 2 
    8           00AAAAAAAA 4 
    9           0AAAAAAAAA 2 (所影响的行数为 3 行) */