500W 记录对于现代数据库来说实在算不上大事。用几个临时表,很快就解决了。
假设原始数据库在这两个表中: tab01, tab02;
可建立以下临时工作表:tmp00, tmp_total
-- 建立索引以提高后面的汇总速度
Create Index i01tmp ON tab01(uid);
Create Index i02tmp ON tab02(uid);
-- 拷贝tab01 中的记录,去掉重复值
Insert into tmp00 (uid, flag) Select uid, 1 From tab01 Group by uid;
-- 拷贝tab02 中的记录,去掉重复值
Insert into tmp00 (uid, flag) Select uid, 2 From tab02 Group by uid;
-- 建立索引以提高后面的汇总速度
Create Index i00tmp ON tmp00(uid);
-- 分组汇总
Insert into tmp_total ( uid, flag ) Select uid, sum(flag) From tmp_all Group by uid;
-- 根据flag字段的汇总值可分3类情况
-- 找出仅存在于tab01 中的uid值
Select uid From tmp_total Where flag=1;
-- 找出仅存在于tab02 中的uid值
Select uid From tmp_total Where flag=2;
-- 找出两个表的交集部分
Select uid From tmp_total Where flag=3;