求救有关not in的问题
- SQL code
select distinct [SRV_PART_NO],[SRV_DESC],[HW_DESC],[HW_PART_NO],[AIC report date][Win8 version] from win7_64_Split_Endwhere win7_64_Split_End.[SRV_PART_NO] not in (select [SRV PART NO] from Commdity_draft_0228)and win7_64_Split_End.[HW_PART_NO] not in (select [HW PART NO] from Commdity_draft_0228)
我是要筛选出win7_64_Split_End中[SRV_PART_NO]与[HW_PART_NO]不存在于Commdity_draft_0228中的.但是使用not in就是筛选不出来,但是事实上是有不同的数据的.
[解决办法]
- SQL code
--> 测试数据: @adeclare @a table (col int)insert into @aselect 1 union allselect 2 union allselect 3--> 测试数据: @bdeclare @b table (col int)insert into @bselect 2 union allselect 3 union allselect 4 union allselect nullselect * from @a where col not in (select col from @b)
[解决办法]
[解决办法]
in其实可以换成 or 然后等于
等于的结构有3种情况,1、等于;2、不等于;3、unknow 不确定。
in里面如有null值就会造成unknown的情况,返回所有的值。
[解决办法]
改not in
为
Not exists
就不存在null不null的问题了
[解决办法]