SQL语句表 TTA   B     C               字段
1  18    12    
2  19    12 
3  20    12
4  18    12
5  18    22 结果
1  18    12  
2  19    12  
3  20    12
5  18    22忽略  B  C  相同的记录

解决方案 »

  1.   

    select * from TT group by B,C having A=max(A)
      

  2.   

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

  3.   

    select max(A) as A,B,C from TT group by B,C
      

  4.   

    create table #TT
    ( A int,B int, C int)insert into #TT
    select 1,18,12
    union all
    select 2,19,12
    union all
    select 3,20,12
    union all
    select 4,18,12
    union all
    select 5,18,22
    select * from #TT group by B,C having A=min(A)
    drop table #TT
      

  5.   

    declare @t table(A int,B int,C int)
    insert @t
    select 1,  18,    12    union all
    select 2,  19,    12    union all
    select 3,  20,    12    union all
    select 4,  18,    12    union all
    select 5,  18,    22 ----方法1:
    select * from @t as a where not exists(select 1 from @t where B = a.B and C =a.c and A < a.A)
    ----方法2:
    select * from @t as a where A = (select min(A) from @t where B = a.B and C =a.c )/*结果
    1  18    12  
    2  19    12  
    3  20    12
    5  18    22
    */
      

  6.   

    create table test(A int,B int,C int)
    insert test select 1,18,12
    union all select 2,19,12
    union all select 3,20,12
    union all select 4,18,12
    union all select 5,18,22select A,B,C from test t
    where not exists
    (
    select 1 from test where B=t.B and C=t.C and A<t.A
    )
      

  7.   

    select min(a) a,b,c from [TT] group by b,c order by a
      

  8.   

    lianqizhi(油条豆腐脑) 
     
    真帅,经测试,完全正确
      

  9.   

    暈樓上一下。你是怎麼測試的,居然完全正確。應該將MAX改為MIN才對的。
      

  10.   

    declare @t table(a int not null,b int null,c int null)
    insert into @t(a,b,c) select 1,  18 ,   12  union all select   
    2,  19,    12 union all select
    3,  20,    12 union all select
    4,  18,    12 union all select
    5 , 18,    22 select A,B,C  from @T AS T  WHERE EXISTS(SELECT * FROM @T  B WHERE T.B<>B.B AND T.C<>B.C) UNION select  TOP 1 A,B,C  from @T AS T  WHERE EXISTS(SELECT * FROM @T  B WHERE T.B=B.B AND T.C=B.C) ORDER BY A