Mysql-子查询

-- 子查询
-- 标量子查询:子查询返回的结果是一个数据(一行一列)
-- 列子查询:返回的结果是一列(一列多行)
-- 行子查询:返回的结果是一行(一行多列)

-- 查询出高于平均身高的信息(high)
-- 1.查出平均身高
select avg(high) from student;

-- 2.查出高于平均身高的信息
select * from student where high>(select avg(high) from student);

-- 查询学生的班级号能够对应的学生名字
-- select name from students where cls_id in (select id from classess);
-- 1.查出所有的班级id
select * from classess;

-- 2.查出能够对应上班级号的学生信息
select * from student where cls_id in (select id from classess);

 

表取自:

Mysql-几张供于学习的表 - 夜黎i - 博客园 (cnblogs.com)

posted on 2023-02-01 13:33  夜黎i  阅读(30)  评论(0)    收藏  举报

导航