如何在一个表里查询两批数据量大的不同数据记录?
一个表里导入了两批数据,根据batch这个字段来确定他们的批次。
我现在想通过c1和c2这两个字段比较确定这个表里发生了变化的数据记录。
两批数据通过c1这个字段关联,根据c2字段的变化来确定这条记录是否变化。
每批数据c1有重复值,我通过下面的语句能找出两批数据相同的记录:
select * from Table where c1 in
(
select distinct a.c1 from
(select distinct c1,c2 from t_Table where batch='1' ) a,
(select distinct c1,c2 from t_Table where batch='2' ) b
where (a.c1=b.c1 and a.c2<>b.c2 )
)
这个结果是正确的;
但我改成下面的语句(把in改成not in)想查询不同的记录:
select * from Table where c1 not in
(
select distinct a.c1 from
(select distinct c1,c2 from t_Table where batch='1' ) a,
(select distinct c1,c2 from t_Table where batch='2' ) b
where (a.c1=b.c1 and a.c2<>b.c2 )
)
结果总是出不来
请问这个问题改怎么解决?
在下不胜感激了!