SQL语言学习随手记——union、intersect、except
2017-10-23 09:45
190 查看
1.并运算——union
e.p.
列出在2009年秋季开课,或在2010年春季开课或两个学期都开课的所有课程:
(select course_id from section where semester = 'Fall' and year = 2009)
union
(select course_id from section where semester = 'Spring' and year = 2010);
注:union运算自动去除重复,如果想保留所有重复,就必须用union all 代替 union。
2.交运算——intersect
e.p.
列出在2009年秋季和2010年春季同时开课的所有课程集合:
(select course_id from section where semester = 'Fall' and year = 2009)
intersect
(select course_id from section where semester = 'Spring' and year = 2010);
注:intersect运算自动去除重复,如果想保留所有重复,就必须用intersect all 代替 intersect。
3.差运算——except
e.p.
列出在2009年秋季学期开课,但不在2010年春季学期开课的所有课程集合:
(select course_id from section where semester = 'Fall' and year = 2009)
except
(select course_id from section where semester = 'Spring' and year = 2010);
注:except运算自动去除重复,如果想保留所有重复,就必须用except all 代替except。
except运算——从其第一个输入中输出所有不出现在第二个输入中的元祖,也即它执行集差操作。
e.p.
列出在2009年秋季开课,或在2010年春季开课或两个学期都开课的所有课程:
(select course_id from section where semester = 'Fall' and year = 2009)
union
(select course_id from section where semester = 'Spring' and year = 2010);
注:union运算自动去除重复,如果想保留所有重复,就必须用union all 代替 union。
2.交运算——intersect
e.p.
列出在2009年秋季和2010年春季同时开课的所有课程集合:
(select course_id from section where semester = 'Fall' and year = 2009)
intersect
(select course_id from section where semester = 'Spring' and year = 2010);
注:intersect运算自动去除重复,如果想保留所有重复,就必须用intersect all 代替 intersect。
3.差运算——except
e.p.
列出在2009年秋季学期开课,但不在2010年春季学期开课的所有课程集合:
(select course_id from section where semester = 'Fall' and year = 2009)
except
(select course_id from section where semester = 'Spring' and year = 2010);
注:except运算自动去除重复,如果想保留所有重复,就必须用except all 代替except。
except运算——从其第一个输入中输出所有不出现在第二个输入中的元祖,也即它执行集差操作。
相关文章推荐
- 步步为营VS 2008 + .NET 3.5(6) - LINQ查询操作符之Distinct、Union、Concat、Intersect、Except、Skip、Take、SkipWhile、TakeWhile、Single、SingleOrDefaul
- 使用 UNION、INTERSECT 和 EXCEPT 对查询结果执行集合运算
- List之Union(),Intersect(),Except() 亦可以说是数学中的并集,交集,差集
- List之Union(),Intersect(),Except() 即并集,交集,差集运算。
- 关于SQL2000的交并差(Intersect、Union、Except)命令说明
- 步步为营VS 2008 + .NET 3.5(6) - LINQ查询操作符之Distinct、Union、Concat、Intersect、Except、Skip、Take、SkipWhile、TakeWhile、Single、SingleOrDefault、Reverse、SelectMany
- UNION, INTERSECT, EXCEPT
- postgresql----UNION&&INTERSECT&&EXCEPT
- SQL Server中几个高级查询运算词(UNION, EXCEPT 和 INTERSECT)
- LINQ to SQL语句(8)之Concat/Union/Intersect/Except
- Intersect, Except, Union, All and Any(1)
- Intersect, Except, Union, All and Any(2)
- LINQ to SQL语句(8)之Concat/Union/Intersect/Except
- linq distinct、union、concat、intersect、except、skip、take、skipwhile、takewhile、
- 关于出现“使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式”错误的可能原因
- 两张结构一样的表如何找不同的记录:UNION - UNION ALL - INTERSECT - MINUS / EXCEPT
- Sql Server2005 Transact-SQL 新兵器学习总结之-EXCEPT和INTERSECT运算符
- List之Union(),Intersect(),Except() 即并集,交集,差集运算。
- 步步为营VS 2008 + .NET 3.5(6) - LINQ查询操作符之Distinct、Union、Concat、Intersect、Except
- Linq 之Concat/Union/Intersect/Except/Distinct