SQL DB2
这是我必须从
开始的SELECT DISTINCT
Last_Name, First_Name, State
FROM AddressTable;
我正在尝试修改查询以查看AddressTable
,如果State = IL
,则应筛选出具有相同Last_Name
的所有人。
如果我的结果低于此值,那么我希望删除姓氏为Jones的所有记录
Smith, Bob, MO
Smith, Eric, MO
Jones, Bob, MO
Jones, Eric, IL
Jones, Tim, NE
答案 0 :(得分:1)
select *
from AddressTable
where Last_Name not in
(
select Last_Name
from AddressTable
where State = 'IL'
)
答案 1 :(得分:0)
我不清楚您是要删除行,还是只想过滤行。这些行被过滤:
SELECT DISTINCT Last_Name, First_Name, State
FROM AddressTable X
WHERE NOT EXISTS (
SELECT 1 FROM AddressTable Y
WHERE X.NAME = Y.NAME
AND Y.STATE = 'IL'
);