我想查找UNION
两个 select 语句中不存在但存在于 table 中的记录t1
。我就是这样做的。有没有更好的方法来做到这一点?
UPDATE t1
SET t1.col1 = 0
WHERE NOT EXISTS (
SELECT tab2.col2
FROM tab2,
tab3
WHERE NOT EXISTS (SELECT *
FROM tab4,
tab5
WHERE tab2.col3 = tab4.col3
AND tab4.col4 = tab5.col4
AND tab5.col5 IN ( 'TT', 'YY' ))
AND tab3.col2 = tab2.col2
AND tab2.col2 NOT IN(SELECT DISTINCT col2
FROM tab2_uk WITH (nolock))
AND t1.col2 = tab3.col2
AND tab3.date IS NULL
AND ( Isnull(tab2.pos, 0) > 0
OR Isnull(tab2.op, 0) > 0
OR Isnull(tab2.co, '-1') <> '-1' )
UNION
SELECT tab6.col2
FROM dbo.tab6 WITH (nolock),
dbo.tab3 WITH (nolock)
WHERE NOT EXISTS (SELECT *
FROM tab4,
tab5
WHERE tab6.col3 = tab4.col3
AND tab4.col4 = tab5.col4
AND tab5.col5 IN ( 'TT', 'YY' ))
AND t1.col2 = tab3.col2
AND tab3.col2 = tab6.col2
AND tab6.po > 0
AND tab3.date IS NULL)