有什么不同?

时间:2015-08-28 16:03:21

标签: sql oracle-sqldeveloper

我想让count计算tlp但不是gal的用户,我有下一个代码:

select count(*) 
from tlp
where ((not EXISTS (SELECT mail 
                    FROM glob
                    WHERE tlp.email1 = glob.mail) 
        AND tlp.email1 IS NOT NULl)
         or ( not EXISTS (SELECT LOGIN
                         FROM   glob 
                         WHERE  tlp.userid = glob.LOGIN     
                        ) 
                        and tlp.email1 is null));

当我运行这个时,我收到了688个用户,当我想用​​这个代码删除那些用户时:

Delete from tlp
  where (( not EXISTS (SELECT mail 
                     FROM   glob 
                     WHERE    tlp.email1 = glob.mail  ) 
         AND tlp.email1 IS NOT NULl)
         or ( not EXISTS (SELECT Login 
                         FROM   glob 
                         WHERE  tlp.userid = glob.login    
                        ) 
                        and tlp.email1 is null));

我有672个已删除的行。 我看不出问题

1 个答案:

答案 0 :(得分:0)

这种方法更简单

select count(*) from 
(
select idField
from etc -- 
minus
select idField
from etc -- these are the records you want to exclude
) derivedTable

你可以弄清楚细节。