select * from [table] a where not exists(select 1 from [table] where A=a.a and b=a.b and c>a.c) and B=2

解决方案 »

  1.   

    select A,B,MAX(C)AS C FROM TABLE1 WHERE B=2 GROUP BY A,B
      

  2.   

    declare @t table(A int,           B  int,           C     int,     D  int,        E  int     ,    F int) 
     insert @t select      1   ,         1   ,         1  ,null,null,null                                            
     insert @t select        1 ,           2 ,           3    ,null,null,null         
      insert @t select       1 ,           3  ,          4    ,null,null,null                                      
      insert @t select       2 ,           2   ,         2 ,null,null,null    
     insert @t select        2 ,           2   ,         3 ,null,null,null    
     insert @t select        2 ,           2   ,         4 ,null,null,null    
    select * from (select * from @t where B=2) t where not exists(select * from(select * from @t where B=2) s where s.a=t.a and s.c>t.c )
    /*
    A           B           C           D           E           F           
    ----------- ----------- ----------- ----------- ----------- ----------- 
    1           2           3           NULL        NULL        NULL
    2           2           4           NULL        NULL        NULL*/
      

  3.   

    select a,max(b) as b,max(c) as c,max(d) as d,max(e) as e,max(f) as f from 表名
    where b=2
    group by a