MySQL数据库 day03
发布时间
阅读量:
阅读量
day03
一、子查询
在一个特定的Select语句内部调用另一个Select子查询时,则称该内置于该Select中的Select为子查询结构。
主查询:是主要查询的对象,第一条select语句
主查询和子查询的关系:
- 子查询被整合到主查询中
- 子 查询作为辅助角色参与主 查询运行,在执行功能上既可以充当过滤条件也可以作为数据来源
- 子 查询不仅自成一体而且是一个完整的select语句
子查询的分类:
1、标量子查询:子查询返回的结果是一个数据(一行一列)
select * from students where age>(select avg(age) from students);
2、列级子查询: 子查询返回的结果是1列
Retrieve the scores from the student table as stu, perform an inner join with the scores table as sc on the student number matching, and select records where the student's age is exactly 18 years old.
3、行级子查询 :子查询的返回结果是一行多列
select * from students where age=(selec
全部评论 (0)
还没有任何评论哟~
