select min(a.A) as A,b.B From a,b
where a.id=b.id
group by b.B

解决方案 »

  1.   

    select max(a)a ,b from tb group by b
      

  2.   

    declare @t table(A int, B varchar(10)) 
    insert @t select 1, 'a' 
    insert @t select 2, 'a' 
    insert @t select 3, 'b' 
    insert @t select 4, 'c' 
    insert @t select 5, 'c' 
    insert @t select 6, 'c' 
    select * from @t t where not exists(select 1 from @t where b=t.b and a<t.a)
    /*A           B
    ----------- ----------
    1           a
    3           b
    4           c(3 行受影响)*/
      

  3.   

    不好意思,看错了,原来是一个表。select min(a),b from A group by b
      

  4.   

    select min(a) a ,b from tb group by b
      

  5.   

    if object_id('Test') is not null drop table Testcreate table Test(A int,B varchar(20))
     
    insert Test 
    select 1,'a' union all
    select 2,'a' union all 
    select 3,'b' union all 
    select 4,'c' union all 
    select 5,'c' union all  
    select 6,'c'
    select a.* 
    from Test a
    where a.A=(select min(b.A) from Test b Group by b.B having a.B=b.B)
      

  6.   

    select A=min(A),B
    from tb
    group by B