集合查询:(确保属性一样)
union:并操作
例1:查询选修了1号课程或2号课程的学生的学号。
select sno from sc where cno='1'
union
select sno from sc where cno='2';
intersect:交操作
例2:查询既选修了1号课程又选修了2号课程的学生的学号。
select sno from sc where cno='1'
intersect
select sno from sc where cno='2';
except:差操作
例3:查询选修了2号课程但没有选修3号课程的学生的学号和课程号
select sno,cno from sc where cno='2'
except
select sno,cno from sc where cno='3';
本文深入解析SQL中的集合操作,包括并集(union)、交集(intersect)和差集(except)。通过具体实例,如查询选修特定课程的学生学号,展示如何使用这些操作来处理数据查询需求。

1124

被折叠的 条评论
为什么被折叠?



