首页 > 解决方案 > 我的代码没有比较 Oracle 中的每一行

问题描述

以下是我的代码,我想选择第二个表中不存在


select t.reg,
       t.dist,
       t.pkey,
       t.n_code,
       t.sum as s17,
       s.sum as s18
  from table1 t,
       (select *
          from table2 t
         where t.pkey is not null) s
 where t.pkey= s.pkey
   and t.reg= s.reg
   and t.dist= s.dist
   and t.a = 99
   and s.a != 99
   and t.n_code= 66
   and t.n_code = s.n_code
   and t.sum > 0
   and t.sum not in s.sum  --not in is not working i think
   and t.reg= 33
   and t.dist= 1

t.sum 没有在第二个表的每一行中进行比较,第一个表的值存在于第二个表中,但存在于另一行中。

代码不搜索其他行以及 PL/SQL

标签: sqloracle

解决方案


Not in不能这样工作。Not inis的语法t.sum Not in (10,20),您也可以使用子查询代替静态值。

但这里Not In不需要。您可以替换以下内容

and t.sum not in s.sum

and t.sum <> s.sum 

推荐阅读