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(*).

  • 相关阅读:
    Markdown
    异异还原
    程序和算法
    运算符
    Java复习1
    复习总结
    为什么Byte是8位,但是却只能表示到127,而不是255?
    笔记的认识
    笔记本触摸板
    电脑热键
  • 原文地址:https://www.cnblogs.com/jkgyu/p/4642285.html
Copyright © 2011-2022 走看看