[在实现数据挖掘一些算法或者是利用空间向量模型来发现相似文档的时候,会遇到求两个集合的交集的情况。以前一般是采用比较笨拙的办法,依次遍历其中一个集 合的元素,然后
需求:从两个不同的结果集(一个是子集,一个是父集),[SELECT ID FROM ( SELECT DISTINCT A.ID AS ID FROM TABLEA A #有ID: 1 2 3 4 5 UNION ALL SELECT DISTINCT B.ID AS ID FROM TABLEB B #有ID: 2 3字段为电话号码phone_number,找出父集中缺少的电话号码,以明确用户身份。
结合网上资料,整理sql如下:
//
mysql取差集
select num FROM
(
select u.code_sn as id,u.phone_number as num from t1 b
left join t2 u
on b.from_user=u.code_sn
where b.to_account='1000' and b.json_info like '%09月份%'
union all
select u.code_sn as id,u.phone_number as num from t3 o
left join t2 u
on o.buyer_code_sn=u.code_sn
where o.seller_account_code_sn='1000' and o.json_info like '%09月份%'
)t3
group by num having coun