SQL语言-----学习随手记20071023

来源:互联网 发布:淘宝网首页全屏代码 编辑:程序博客网 时间:2024/06/06 09:05

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运算——从其第一个输入中输出所有不出现在第二个输入中的元祖,也即它执行集差操作。



原创粉丝点击