【发布时间】:2015-03-10 07:21:35
【问题描述】:
请帮助以下查询
select * from processed_h where c_type not in (select convert(int,n_index) from index_m where n_index <>'0') **-- 902 rows**
select * from processed_h where c_type not in (2001,2002,2003) **-- 902 rows**
select convert(int,n_index) from index_m where n_index <>'0' **--- 2001,2002,2003**
我尝试将 not in 转换为 LEFT JOIN,如下所示,但它给了我 40,000 行返回了我做错了什么
select A.* from processed_h A LEFT JOIN index_m B on A.c_type <> convert(int,B.n_index) and B.n_index <>'0' --40,000 + rows
【问题讨论】:
-
欢迎来到 SO,请在标签和标题中指定查询语言。
-
您使用的是哪个 DBMS?
-
我使用的是 SYABSE 15.7
-
我敢打赌,LEFT JOIN 正在生成一些带有 NULL 值的结果,这些结果被排除在 where 子句中,因为 NULL 不能等于任何东西。
-
是的,我得到了 NULL ,但是你能告诉我为什么当我将它用作 (2001,2002,2003) 时我没有得到 NULL 值