很简单
select * form tbName a
where b='a'
and not exists (
select 1 from tbName
where B='a'
and a<a.a
)

解决方案 »

  1.   


    DECLARE @B NVARCHAR(5)
    SET @B = 'a'
    SELECT * FROM tb where A IN(select MAX(A) from tb where B=@B)
      

  2.   

    declare @t table (id int,A int,B varchar(10))
    insert into @t values(1,1,'a')
    insert into @t values(2,1,'a')
    insert into @t values(3,2,'a')
    insert into @t values(4,2,'a')
    insert into @t values(5,3,'a')
    insert into @t values(6,3,'a')
    insert into @t values(7,1,'b')
    insert into @t values(8,1,'b')
    insert into @t values(9,2,'b')select * from @t a where a in(select min(A) from @t where b=a.b and b='a')
      

  3.   

    select * form tbName a
    where b='a'
    and not exists (
    select 1 from tbName
    where a.b = b
    and a<a.a
    )
      

  4.   

    --3楼就把b='a'放在子查询外做条件:select 
    *
    from 
    @T t
    where
    a in(select min(a) from @t where b=t.b) and b='a'
      

  5.   


    --换一种写法
    declare @t table (id int,A int,B varchar(10))
    insert into @t values(1,1,'a')
    insert into @t values(2,1,'a')
    insert into @t values(3,2,'a')
    insert into @t values(4,2,'a')
    insert into @t values(5,3,'a')
    insert into @t values(6,3,'a')
    insert into @t values(7,1,'b')
    insert into @t values(8,1,'b')
    insert into @t values(9,2,'b')select 
    *
    from 
    @T t
    where
    B+rtrim(A) in (select min(B+rtrim(A)) from @t group by B) and b='a'