MySql查询-子查询

2020-03-20  本文已影响0人  GaoYuan117

子查询

在一个 select 语句中,嵌入了另外一个 select 语句, 那么被嵌入的 select 语句称之为子查询语句

主查询

主要查询的对象,第一条 select 语句

主查询和子查询的关系

子查询分类

标量子查询

  1. 查询班级学生平均年龄
  2. 查询大于平均年龄的学生

查询班级学生的平均身高

select * from students where age > (select avg(age) from students);

列级子查询

select name from classes where id in (select cls_id from students);

行级子查询

select * from students where (height,age) = (select max(height),max(age) from students);

子查询中特定关键字使用

上一篇 下一篇

猜你喜欢

热点阅读