zoukankan      html  css  js  c++  java
  • Oracle not in子连接查询不到值的问题(not in 不能查询null数据)

    前几天在项目中,做数据导入时,发现not in和in 查出来的条数不互补。ATABLE2明明中有些记录在ATABLE3中不存在,但是not in时查不出记录。 

    CREATE TABLE ATABLE2
       ( "MRID" VARCHAR2(20 BYTE)
       )

    CREATE TABLE ATABLE3"
       ( "MRID" VARCHAR2(20 BYTE)
       )

    查询语句如下

    select count(*) from atable2 where mrid not in (select mrid from atable3),查询结果为0。

    经过几番检查,发现的not in 和null的问题。atable3表中存在mrid为null的记录,此时not in 查询不到值。

    修改方案如下:在子查询中增加非空过滤

    select count(*) from atable2 where mrid not in (select mrid from atable3 where mrid is not null)

    完毕!

    ps:count统计函数对null值也不适用,需用count(*).

  • 相关阅读:
    浅拷贝和深拷贝
    squeezenet
    7常用函数
    6表的约束
    5select的运用
    4操作符
    3基本数据操作
    2基本数据类型
    1mysql的安装
    16多态
  • 原文地址:https://www.cnblogs.com/jkgyu/p/4642285.html
Copyright © 2011-2022 走看看