select a, b, c, nullif( max( case when d is null then '999999' else d end ), '999999' )
from M
group by a, b, c

解决方案 »

  1.   

    能有不用nullif实现么。。我不是在sql上运行,好像没有nullif这个函数。
      

  2.   

    selec t1.a,t1.b,t1.c,case when t3.Dcount>=1 then null else t2.D end as D from 
    (select  A,B,C from M group by a, b, c ) t1
    left join 
    (select  A,B,C,max(D) as D from M group by a, b, c ) t2
    on t1.a=t2.a and t1.b=t2.b and t1.c=t2.c
    left join 
    (select  A,B,C, count(D) as DCount from M where D is null group by a, b, c ) t3
    on t1.a=t3.a and t1.b=t3.b and t3.c=t3.c
      

  3.   

    select a, b, c, max(d) 
    from M 
    group by a, b, c就可以了。
      

  4.   

    对不起,没仔细看,select a,b,c,case when min(case when d is null then -1 end) = -1 then null else max(d) end 
    from t 
    group by a, b ,c其实这就是二楼的方法。