• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

表里存在NULL值导致not in子查询失效的问题

mysql 搞代码 4年前 (2022-01-09) 85次浏览 已收录 0个评论

表里存在NULL值导致not in子查询失效的问题 –这是我第一次给业务写的SQL语句,查询来数据为0,当时没考虑太多就发出去了。 后业务给我看了几条测试数据,我发现确实查询结果不对。br–再看语句逻辑确实没错,后经过排查是BB里有几行cust_id为NULL导致not in

表里存在NULL值导致not in子查询失效的问题

–这是我第一次给业务写的SQL语句,查询来数据为0,当时没考虑太多就发出去了。 后业务给我看了几条测试数据,我发现确实查询结果不对。
–再看语句逻辑确实没错,后经过排查是BB里有几行cust_id为NULL导致not in 查询结果失效。 http://www.2cto.com

–改良前的语句
select * from AA a with(nolock)
where a.status_code='04'

and a.issue_date>='2012-01-01' and a.issue_date<='2012-10-30'

and LEFT(a.manorg_code,4)='8640'

and a.cust_id not in

(

select a

本文来源gaodai.ma#com搞##代!^码@网3

a.cust_id from BB aa with(nolock) where aa.sheet_type='Q' and aa.acttype_code in ('01','02','16','19')

)

–改良后的语句

select * from AA a with(nolock)

where a.status_code='04'

and a.issue_date>='2012-01-01' and a.issue_date<='2012-10-30'

and LEFT(a.manorg_code,4)='8640'

and a.cust_id not in

(

select ISNULL(aa.cust_id,'') from BB aa with(nolock) where aa.sheet_type='Q' and aa.acttype_code in ('01','02','16','19')

)


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:表里存在NULL值导致not in子查询失效的问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址