栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

11-子查询和嵌套查询

11-子查询和嵌套查询

子查询和嵌套查询 子查询

where (值是固定的)

where (select * from)

-- 查询java 的所有考试结果(学号 科目编号 成绩)降序排列
-- 也可以用联表查询
select `studentNo`,`subjectNo`,`studentResult`
from `result` 
where subjectNo=(
    select subjectNo from subject where subjectName='java'
)
order by studentResult DESC



-- 分数不小于80分的学生的学号和姓名
-- 在这个基础上增加一个条件 名称为java的
-- 也可以用联表查询
select distinct s.`studentNo`,`studentName`
from  student s
inner join result r
on r.studentNo = s.studentNo
where  `studentResult`>=80 AND `subjectNo`=(
	select  `subjectNo` from subject
    where `subjectName`='java'
)

在改造(由里及外)

select `studentNo`,`studentName` from student where studentNo IN(
select `studentNo` from result where studentResult > 80 AND subjectNo =(
    select `subjectNo` from subject where `subjectName`='java'
)
)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/278533.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号