zoukankan      html  css  js  c++  java
  • not in查询不出数据问题

       

    select ID from SmartCustomer where ID not in (select distinct CustomerID from SmartPromoter where CustomerID)
    改为
    select ID from SmartCustomer where ID not in (select distinct CustomerID from SmartPromoter where CustomerID is not null)

    这个问题的根源在于null,众所周知,当判断一个值是否为null的时候,sql server要用is null 或者is not null,  在SQL Server中,Null值并不是一个值,而是表示特定含义,其所表示的含义是“Unknow”,可以理解为未定义或者未知,因此任何与Null值进行比对的二元操作符结果一定为Null,包括Null值本身。而在SQL Server中,Null值的含义转换为Bool类型的结果为False。 SQL Server提供了“IS”操作符与Null值做对比,用于衡量某个值是否为Null。

    这里还要说一下not in的问题,应尽量避免使用not in,not in结果不准确,性能效率低。可以采用not exists方案替代

    select ID from SmartCustomer a where  not exists (select ID from SmartPromoter b where a.ID=b.CustomerID)
  • 相关阅读:
    工厂方法和抽象工厂
    waterMarkTextBox
    button hot key 热键
    wpf 双击行。。获得行信息
    update comboBox
    WPF标准控件模板查看程序(文件里面)
    Sp EF输出 临时表
    tree view
    Ubuntu 常用命令
    ESP8266 开发记录
  • 原文地址:https://www.cnblogs.com/xiaopotian/p/6826628.html
Copyright © 2011-2022 走看看