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
union all
select * from tablename where a in (select a from tablename group by a having count(b)>1) and b=1
可能我表述的不太清楚,上面的数值是我图方便写的,其实每个数值其实是个字符串,
我想返回这样记录集:表中有两个列a,b;列a中可能有值相同,这时我取b为指定值的的行,其他行不管b为何值,全部取出。
select a,b from #tb aa where id=(select min(id) from #tb where a=aa.a)
drop table #tb
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