设为首页 加入收藏

TOP

表里存在NULL值导致not in子查询失效的问题
2014-11-24 07:55:47 来源: 作者: 【 】 浏览:2
Tags:表里 存在 NULL 导致 not 查询 失效 问题

表里存在NULL值导致not in子查询失效的问题
--这是我第一次给业务写的SQL语句,查询来数据为0,当时没考虑太多就发出去了。 后业务给我看了几条测试数据,我发现确实查询结果不对。
--再看语句逻辑确实没错,后经过排查是BB里有几行cust_id为NULL导致not in 查询结果失效。 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 aa.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')
)
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLite在micro上的移植 下一篇undo损坏案列

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++模板 (template) (2025-12-26 15:49:49)
·C 语言中模板的几种 (2025-12-26 15:49:47)
·模板(泛型) - C语 (2025-12-26 15:49:44)
·C语言中,“指针”用 (2025-12-26 15:20:18)
·在c语言的指针运算中 (2025-12-26 15:20:15)