Java教程

SQL集合运算(并、交、差)

本文主要是介绍SQL集合运算(并、交、差),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

集合运算

unionintersectexcept对应于∪、∩、-运算

并运算union

union自动去除重复,如果想保留所有重复,则用union all代替union

(select course_id
from section
where semester = 'Fall' and year = 2009)
union
(select course_id
from section
where semester = 'Spring' and year = 2010)

交运算intersect

intersect自动去除重复,如果想保留所有重复,则用intersect all代替intersect

(select course_id
from section
where semester = 'Fall' and year = 2009)
intersect
(select course_id
from section
where semester = 'Spring' and year = 2010)

差运算

except在操作前自动去除输入重复,如果想保留所有重复,则用except all代替except

(select course_id
from section
where semester = 'Fall' and year = 2009)
except
(select course_id
from section
where semester = 'Spring' and year = 2010)
这篇关于SQL集合运算(并、交、差)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!