mysql取差集、交集、并集

博客分类: Mysql数据库

需求:从两个不同的结果集(一个是子集,一个是父集),字段为电话号码phone_number,找出父集中缺少的电话号码,以明确用户身份。
结合网上资料,整理sql如下: //mysql取差集 Java代码 收藏代码
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='' 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='' and o.json_info like '%09月份%' )t3
group by num having count(num)=1 //mysql取交集 Java代码 收藏代码
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='' 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='' and o.json_info like '%09月份%' )t3
group by num having count(num)=2 //mysql取并集 Java代码 收藏代码
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='' 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='' and o.json_info like '%09月份%' )t3

mysql取差集、交集、并集的更多相关文章

  1. Linq 取差集 交集等

    string goodsList = context.Request.Form["goodsList"]; if (!string.IsNullOrEmpty(goodsList) ...

  2. sql server中取交集、差集和并集的语法

    这里简单总结下在SQL Server中取交集.差集和并集的语法. 交集:INTERSECT(适用于两个结果集) SELECT ID, NAME FROM YANGGB1 INTERSECT SELEC ...

  3. 关于C++里set_intersection(取集合交集)、set_union(取集合并集)、set_difference(取集合差集)等函数的使用总结

    文章转载自https://blog.csdn.net/zangker/article/details/22984803 set里面有set_intersection(取集合交集).set_union( ...

  4. List<T>取交集、差集、并集

    1.  取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , 9 }List B : { 4 , 3 , 9 }var intersectedList = list1.Inte ...

  5. (java/javascript) list 交集 并集 差集 去重复并集

    java list 交集 并集 差集 去重复并集 package com; import java.util.ArrayList; import java.util.Iterator; import ...

  6. C# 数组的交集、差集、并集

    C# 数组的交集.差集.并集 工作中经常会用这方面的知识来检查那些字段是必须输入的,那些是禁止输入. using System; using System.Collections.Generic; u ...

  7. SQL求 交集 并集 差集

    故事是这样的….. 故事情节: 表 tb_test 有两列, colA , colB; 求 colA , colB 的并交差集… -- 计算并集 SELECT DISTINCT colB FROM t ...

  8. MySQL实现差集(Minus)和交集(Intersect)

    原文链接: http://www.linuxidc.com/Linux/2014-06/103551.htm MySQL没有实现Minus和Intersect功能,就像它也没有实现cube的功能一样. ...

  9. java8 集合求差集、并集、交集

    前言 java8里最大亮点是lambda,让我们用习惯C# linq的语法,也能眼前一亮.但是比起C#的语法糖还是差的很远. 差集.并集.交集 @Test public void test1(){ L ...

随机推荐

  1. c++ shared_ptr的使用

    shared_ptr.是c++为了提高指针安全性而添加的智能指针,方便了内存管理.功能非常强大,非常强大,非常强大(不单单是shared_ptr,配合week_ptr以及enable_share_fr ...

  2. CO15批次确定,标准的太蛋疼了

    1.批次确定的配置,之前有转过,自己也动手配过,可以是可以,但是蛋疼,用户不愿意去弹出的界面选批次...2.因为这边的批次全部是按年月日+流水生成的,所以在批次确定这里就需要按照批次的号来排序选择了 ...

  3. virtualbox不能安装64位操作系统

    现在virtualbox 还是比较好用的虚拟机.新建立一个不同的操作系统还是非常方便. virtualbox下载地址  https://www.virtualbox.org/wiki/Download ...

  4. sun.misc.BASE64Encoder图片编码,并在页面显示

    Data URI scheme是在RFC2397中定义的,目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入.在上面的Data URI中,data表示取得数据的协定名称,image/pn ...

  5. jqgrid操作列循环显示三个按钮

    首先ajax取数据 $.ajax( { type: "get", url: "../../MECManage/TJYY/collect", cache: fal ...

  6. python爬虫---requests库的用法

    requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 因为是第三方库,所以使用前需要cmd安装 pip install requests 安装完成后import一下 ...

  7. [LeetCode] 108. Convert Sorted Array to Binary Search Tree ☆(升序数组转换成一个平衡二叉树)

    108. Convert Sorted Array to Binary Search Tree 描述 Given an array where elements are sorted in ascen ...

  8. InnoDB行记录格式(compact)、InnoDB数据页结构

    1. compact 行记录格式: 变长字段长度列表,null标志位,记录头信息,列1数据,列2数据 …… 记录头信息中包含许多信息,只列举一部分: 名称 大小 描述 deleted_flag 1bi ...

  9. 创建含有多module的springboot工程(八)

    创建根工程 创建一个maven 工程,其pom文件为: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version="1.0" enc ...

  10. span 超出部分换行

    span{ word-break: normal; width: auto; display: block; white-space: pre-wrap; word-wrap: break-word; ...