日期:2014-05-18  浏览次数:20525 次

求救有关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_End
where 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

--> 测试数据: @a
declare @a table (col int)
insert into @a
select 1 union all
select 2 union all
select 3

--> 测试数据: @b
declare @b table (col int)
insert into @b
select 2 union all
select 3 union all
select 4 union all
select null

select * from @a where col not in (select col from @b)

------解决方案--------------------
探讨

引用:

SQL code

--> 测试数据: @a
declare @a table (col int)
insert into @a
select 1 union all
select 2 union all
select 3

--> 测试数据: @b
declare @b table (col int)
insert int……

------解决方案--------------------
in其实可以换成 or 然后等于

等于的结构有3种情况,1、等于;2、不等于;3、unknow 不确定。

in里面如有null值就会造成unknown的情况,返回所有的值。
------解决方案--------------------
改not in

Not exists
就不存在null不null的问题了
------解决方案--------------------
探讨

引用:

改not in

Not exists
就不存在null不null的问题了


这位仁兄,语法报错