--子查询:就是把一个查询结果作为另一个查询的数据源
SELECT * FROM MyStudents
----(1) 独立子查询
SELECT * FROM
(select FName,FAge,FGender
from MyStudents
where FAge<=24 and FAge>=18) as Tbl1
where FGender='女' and FName LIKE '张%'
--
select
最高分=(select MAX(FMath) from MyStudents),
最低分=(select MIN(FMath) from MyStudents),
平均分=(select AVG(FMath) from MyStudents)
----查询高二二班的所有学生,学生姓名\性别\学号...
Use School
select * from Student
select * from Class
--在where中 应用子查询
--相关子查询
select * from Student
where
exists(select *
from Class
where cName='高二二班' and Class.clsId=Student.sClassId)
----查询高二二班和高二一班的所有学生,学生姓名\性别\学号...
select * from Student