|
列值为: 1 1 2 0 2 1 3 0 返回:a b 1 1 2 1 3 0 除了返回列a中值相同但b=1的行外,还要返回其他所有行。 |
|
|
|
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 |
|
|
select a,max(b) from 表 group by a
|
|
|
楼上的老大:
可能我表述的不太清楚,上面的数值是我图方便写的,其实每个数值其实是个字符串, 我想返回这样记录集:表中有两个列a,b;列a中可能有值相同,这时我取b为指定值的的行,其他行不管b为何值,全部取出。 |
|
|
用临时表:
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 |
|
|
--我理解错了楼主的意思.应该是:
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 |
|