一.并集:

需求:汇总t1、t2两表的数据

mysql、postgresql、oracle数据库取并集都是用union/union all关键字,不再赘述

二.交集:

需求:选出既在t1表又在t2表的数据

1.mysql数据库取交集,没有对应的关键字,只能把所有要查询的字段都加到where条件上,如下

select t1.name, t1.age from t1, t2 where t1.name = t2.name and t1.age = t2.age   //如果t1, t2不是表而只是结果集的话,只需要加上with t1 as(...), t2 as (...)就可以了

2.postgresql/oracle数据库取交集,可以用intersect关键字,如下

select t1.name, t1.age from t1

intersect

select t2.name, t2.age from t2

三.差集:

需求:选出在t1表中但不在t2表中的数据

1.mysql数据库取差集,也没有对应的关键字,有2种方式:

①.用not in

select name, age from t1

where (t1.name, t1.age) not in (select name, age from t2)

注意,where后面字段如果有多个,必须用括号括起来,同时子查询语句也必须用括号括起来

not in这种方式虽然写法简单,但是如果两个表的数据很多的话,那查询起来非常慢

②.用连表查询

sql92:

select t1.name, t1.age from t1

where t1.name != t2.name or t1.age != t2.age

或是

sql99:

select t1.name, t1.age inner join t2

on t1.name != t2.name or t1.age != t2.age

当然,如果t1、t2有多个字段的话,就要一个一个比对,然后用or连接起来

必须用内连接,这点想想左连接和右连接查出的结果集就明白了。

2.postgresql取差集,可以用except关键字,如下:

select t1.name, t1.age from t1

except

select t2.name, t2.age from t2

3.oracle数据库取差集,可以用minus关键字,如下

select t1.name, t1.age from t1

minus

select t2.name, t2.age from t2

集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils探究的更多相关文章

  1. 集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils探究(转)

    之前一直以为集合工具类只有CollectionUtils,主要用它的isEmpty(final Collection<?> coll)静态方法来判断一个给定的集合是否为null或者是否长度 ...

  2. 集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils的使用

    主要用它的isEmpty(final Collection<?> coll)静态方法来判断一个给定的集合是否为null或者是否长度为0.最近才发现此工具类还可以取集合的交集.并集.甚至差集 ...

  3. Commons-Collections 集合工具类的使用

    package com.bjsxt.others.commons; import java.util.ArrayList; import java.util.List; import org.apac ...

  4. 集合工具类 - CollectionUtil.java

    集合工具类,提供数组转LIST.数组转SET.合并集合.计算笛卡儿积等方法. 源码如下:(点击下载 -  CollectionUtil.java.ArrayUtil.java.commons-lang ...

  5. [Guava学习笔记]Collections: 集合工具类

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3861431.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  6. Collections 集合工具类

    集合工具类  包括很多静态方法来操作集合list 而Collections则是集合类的一个工具类/帮助类,其中提供了一系列静态方法,用于对集合中元素进行排序.搜索以及线程安全等各种操作. 1) 排序( ...

  7. 实用的 集合工具类 和 String工具类

    集合工具类:CollectionUtil method: 1.isNotEmpty() 不为空 2.isEmpty() 为空 举例:map集合         Map<String,String ...

  8. Collections集合工具类,集合嵌套,集合综合案例斗地主

    1 Collections集合工具类 (可以对比Arrays工具类共同记忆) 常用方法: 例: import java.util.ArrayList; import java.util.Collect ...

  9. java之集合工具类Collections

    Collections类简介 java.utils.Collections 是集合工具类,用来对集合进行操作.此类完全由在 collection 上进行操作或返回 collection 的静态方法组成 ...

随机推荐

  1. asp.net学习视频资料地址链接

    ASP.NET开发学习视频教程大全(共800集) http://felix520wj.blog.51cto.com/7129746/1548458 http://study.163.com/cours ...

  2. MVC3+EF4.1学习系列(二)-------基础的增删改查和持久对象的生命周期变化

    上篇文章中 我们已经创建了EF4.1基于code first的例子  有了数据库 并初始化了一些数据  今天这里写基础的增删改查和持久对象的生命周期变化 学习下原文先把运行好的原图贴来上~~ 一.创建 ...

  3. 对于querystring取值时候发生+号变空格的问题

    今天遇到这个问题,在网上找了几个答案,解决了问题,很高兴,所以贴出来给大家分享一下: URL如下 http://127.0.0.1/test/test.aspx?sql= and id='300+' ...

  4. apicloud

    <!doctype html> <html class="no-js"> <head> <meta charset="utf-8 ...

  5. 循环移位法和数据拼接法基于led

    功能描述 让led每隔0.5s从两边向中间闪烁,然后在从中间向两边闪烁,不断循环 项目实现 开发板 晶振为50M,那么达到0.5s时计数器count1需要达到24_999_999这么多次数 计数器代码 ...

  6. ajax 假上传文件

    1. <form name="certForm" id="certForm" method="post" action="x ...

  7. CentOS安装配置Tomcat7

    1.下载apache-tomcat-7.0.62.tar.gz 2.解压:tar -zxvf apache-tomcat-7.0.62.tar.gz 3.配置环境变量: 进入安装目录:(/usr/lo ...

  8. 利用xcopy命令实现本地文件复制到远程服务器的方法

    net use \\192.168.1.198\ipc$ Zqf198703 /user:royalpeak xcopy g:\backup\*.* \\192.168.1.198\数据备份 /D / ...

  9. 3.Perl 多线程:Threads(exit thread_only)

    还可以在导入threads模块时设置: use threads ('exit' => 'thread_only');

  10. 1001. A+B Format

    Calculate a + b and output the sum in standard format -- that is, the digits must be separated into ...