读书人

比较过滤得有关问题

发布时间: 2012-03-14 12:01:12 作者: rapoo

比较过滤得问题,
一个表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)

读书人网 >SQL Server

热点推荐