mysql取差集、交集、并集
2017-04-12 16:34
567 查看
需求:从两个不同的结果集(一个是子集,一个是父集),字段为电话号码phone_number,找出父集中缺少的电话号码,以明确用户身份。
结合网上资料,整理sql如下:
//mysql取差集
//mysql取交集
//mysql取并集
结合网上资料,整理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 count(num)=1
//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 t1 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 count(num)=2
//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 t1 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
相关文章推荐
- mysql中交集,并集,差集,左连接,右连接
- MySQL 的并集、交集和差集
- mysql取差集、交集、并集
- MySQL 并集、交集、差集
- MySQL 的并集、交集和差集 交集和差集类似oracle中minus的用法
- mysql中交集,并集,差集,左连接,右连接
- mysql中实现并集、交集、差集、内联结、外联结、3张以上表的联结、交叉联结
- MySQL 的并集、交集和差集
- MySQL 的并集、交集和差集
- Java正则表达式--字符集范围:并集、交集和差集
- 求两个数组的交集、并集和差集算法分析与实现(转自http://blog.sina.com.cn/s/blog_616e189f0100mrdn.html)
- DataTabe(DataRow)之间比较求交集、并集、差集
- 交集、并集、差集、笛卡尔积 [l转帖]
- SQL测试-------交集、并集、差集、笛卡尔积
- SQL的并集UNION,交集JOIN,交叉连接(CROSS JOIN笛卡尔积),差集(NOT IN)
- LINQ操作数组代码(交集,并集,差集,最值,平均,去重复)
- bash技巧:求集合的交集、并集、差集、对称差集
- 我的SQL测试-------交集、并集、差集、笛卡尔积
- sql 交集 差集 并集 笛卡尔积