栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

MYSQL入门与进阶(十三)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MYSQL入门与进阶(十三)

目录
    • 在查询条件的位置作为条件存在


在查询条件的位置作为条件存在

A.使⽤in
Eg1:查询考试不及格的学⽣名单
B.使⽤not in
Eg2:查询没有参加基于C语⾔理解软件编程考试的学⽣名单
– A.使用in
– Eg1:查询考试不及格的学生名单
select studentid from exam where exam<60
select * from studentinfo where studentid in(
select studentid from exam where exam<60
)
– B.使用not in
– Eg2:查询没有参加基于C语言理解软件编程考试的学生名单
select * from subject where subjectname=‘基于C语言理解软件编程’
select studentid from exam where subjectid=1
select * from studentinfo where studentid not in(
select studentid from exam where subjectid=(
select subjectid from subject where subjectname=‘基于C语言理解软件
编程’) )
C.使⽤all
Eg3:查询成绩⽐“C003”这⻔课程的任意成绩都⼤的学⽣考试信息。
D.使⽤any
Eg4:查询成绩⽐“C003”这⻔课程的某⼀个成绩⾼的学⽣考试信息
C.使用all:所有>all(子查询,返回值是多行一列),
如果值大于子查询结果中的所有才算true应该被显示否则不显示:>max Eg3:查询成绩比“基于C语言理解软件编程”这门课程的所有人成绩都大的学生考试信息。

 select * from `subject` where subjectname='基于C语言理解软件编程'
 select * from exam where subjectid=1
 select * from exam where exam>all(
 select exam from exam where subjectid=(
select subjectid from `subject` where subjectname='基于C语言理解软件
编程'));
 select * from exam where exam>(
 select max(exam) from exam where subjectid=(
select subjectid from `subject` where subjectname='基于C语
言理解软件编程'))
 -- D.使用any:任意,>any(子查询) :大于子查询中任意一个值即可,>min
 -- Eg4:查询成绩比“C003”这门课程的某一个成绩高的学生考试信息
 select * from exam where exam>any(
 select exam from exam where subjectid=(
select subjectid from `subject` where subjectname='基于C语言理解软件
编程' );
select * from exam where exam>(
select min(exam) from exam where subjectid=(
select subjectid from `subject` where subjectname='基于C语
言理解软件编程' ) );
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1029415.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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