当前位置: 代码迷 >> Sql Server >> 比较过滤得有关问题
  详细解决方案

比较过滤得有关问题

热度:62   发布时间:2016-04-27 20:53:11.0
比较过滤得问题,
一个表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)
  相关解决方案