select
 f1=case when left(f1,2) in ('05','06','07') then '05'+substring(f1,3,2) else f1 end,
 f2=sum(f2),f3=min(na)
from t
group by case when left(f1,2) in ('05','06','07') then '05'+substring(f1,3,2) else f1 end

解决方案 »

  1.   

    Softlee81307(孔腎)这个办法倒是不错,问题到是解决了,但如果是合并为06呢。那不是就不能用min也不能用max了。
      

  2.   

    select
       a.f1,
       b.f2,
       f3=a.na
    from
       t a,
       (select
            f1 = case when(left(f1,2) in('06','07')) then '05'+stuff(f1,1,2,'') else f1 end,
            f2 = sum(f2)
        from 
            t
        group by
            case when(left(f1,2) in('06','07')) then '05'+stuff(f1,1,2,'') else f1 end) b
    where
       a.f1 = b.f1
      

  3.   

    同一 f1 对应了几个 na ,那是你的问题若取05对应的那个,如libin_ftsafe(子陌红尘)所写
      

  4.   

    用 libin_ftsafe(子陌红尘) 方法倒是不存在问题,可惜的是我用的是sybase不是SQLServer,不能那样写。sybase不支技这样的临时表。
      

  5.   

    select
    f1=(case when f1 in ('0501','0601','0701') then '0501'
    when  f1 in ('0702','0502') then '0502' 
    when f1='0703' then '0503'
    else f1 end),
    f2=sum(f2),f3=min(na)
    from 表a
    group by f1