数据库(三)关系数据库标准语言SQL(2)
2016-12-06 20:20
549 查看
连接查询
查询同时涉及两个以上的表,对应代数运算中的连接。
等值/非等值连接
外连接
嵌套查询
带有in谓词
只返回查询的逻辑值true/false
全称量词的查询
子类型 all/some
集合操作
并union 交intersect 差except
选择新数据源
select sno,sname avg_grade from student ,(select sno,avg(grade) as avg_grade from sc group by sno)...
查询同时涉及两个以上的表,对应代数运算中的连接。
等值/非等值连接
select Student.*,SC.* from Student,SC where Student.Sno = SC.Sno and SC.Grade>90;自身连接
select first.Cno, second.Cpno from Course first, Course second where first.Cpno = second.Cno;
外连接
select Student.Sno from Student left outer join SC on (Student.Sno = SC.Sno);
嵌套查询
带有in谓词
select Sno from Student where Sdept in (select Sdept from Student where Sname = '张三');带有比较关系运算符
select Sno from SC x where Grade >= (select AVG(Grade) from SC y where y.Sno = x.Sno);带有any(任意值)/all(所有值)
select Sname from Student where Sage < any(select Sage from Student where Sdept = 'CS') and Stept <>'CS';带有exist
只返回查询的逻辑值true/false
select Sname from Student where not exist (select * from SC where Sno = Student.sno and Cno = '1'); 选出没有选1号课程的学生姓名
全称量词的查询
选出至少选择了95001号同学所选全部课程的学生的学号 select distinct Sno from SC x where not exists ( select * from SC y where y.Sno = 95001 and not exists( select * from SC z where z.Sno = x.Sno and z.Cno = y.Cno ) );
子类型 all/some
select Sname from Student where 60 > all(select Score from SC where...);
集合操作
并union 交intersect 差except
select * from Student where Sdept='CS' istersect select * from student where Sage<=19;
选择新数据源
select sno,sname avg_grade from student ,(select sno,avg(grade) as avg_grade from sc group by sno)...
相关文章推荐
- 文章标题关系数据库标准语言SQL-2
- 数据库系统原理复习题(三)——关系数据库标准语言SQL
- 对关系数据库标准语言SQL的简单认识
- 3-1关系数据库标准语言SQL
- 数据库系统概论复习总结3 --- 第二章关系数据库标准语言SQL
- 第3章 关系数据库标准语言SQL(数据库系统概论)
- 第3部分 关系数据库标准语言 SQL(2)
- 关系数据库标准语言SQL基础2
- 第三章 关系数据库标准语言SQL
- [网络问题,截图以后再传]本实验是设计性实验。目的在于使用关系数据库标准语言SQL,掌握视图和索引的操作。
- 【数据库系统概论】-关系数据库标准语言SQL(3)
- 数据库笔记3————关系数据库标准语言SQL上(SQL的数据定义和数据更新)
- 关系数据库标准语言SQL的基本问答
- 数据库 - 关系数据库标准语言SQL
- 关系数据库标准语言SQL(二)
- 【数据库系统概论】-关系数据库标准语言SQL(1)
- 【数据库系统概论】-关系数据库标准语言SQL(2)
- 数据库原理(四)--关系数据库标准语言SQL(一)
- 第3部分 关系数据库标准语言 SQL
- 关系数据库标准语言SQL基础1续