日期:2014-05-19  浏览次数:20466 次

比较过滤得问题,
一个表table
字段1     字段2
A               1
B               1
C               1
D               1
A               2
X               2
Y               2
B               2
Z               2

从这里找出
X               2
Y               2
Z               2
怎么做?

------解决方案--------------------
select
t.*
from
[table] t
where
t.字段2=2
and
not exists(select 1 from [table] where 字段1=t.字段1 and 字段2=1)
------解决方案--------------------
select * from [table] a where not exists(select 1 from [table] b where a.字段1=b.字段1 and b.字段2=1)