select * from tablename where a in (select a from tablename group by a having count(b)=1)
union all
select * from tablename where a in (select a from tablename group by a having count(b)>1) and b=1

解决方案 »

  1.   

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

  2.   

    楼上的老大:
    可能我表述的不太清楚,上面的数值是我图方便写的,其实每个数值其实是个字符串,
    我想返回这样记录集:表中有两个列a,b;列a中可能有值相同,这时我取b为指定值的的行,其他行不管b为何值,全部取出。
      

  3.   

    用临时表:select id=identity(int,1,1),* into #tb from tablea
    select a,b from #tb aa where id=(select min(id) from #tb where a=aa.a)
    drop table #tb
      

  4.   

    --我理解错了楼主的意思.应该是:select * from tablea aa
    where (select sum(1) from tablea where a=aa.a)>1 and b=1) or (select sum(1) from tablea where a=aa.a)=1