MySQL 嵌套查询_嵌套查询和嵌套结果的区别

MySQL 嵌套查询_嵌套查询和嵌套结果的区别自测题:1、查询哪些课程没有人选修列出课程号和课程名;[code]selectcno,cnamefromcoursewherecnonotin(selectdistinctcnofromsc)[/code]2、用子查询实现如下查询:(1)查询选修了1号课程的学生姓名和所在系;[code]selectsname,snofromstudentwheresnoin(select…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

自测题:

1、查询哪些课程没有人选修列出课程号和课程名;

[code]select cno,cname

from course

where cno not in(

select distinct cno

from sc)[/code]

2、用子查询实现如下查询:

(1)查询选修了1号课程的学生姓名和所在系;

[code]select sname,sno

from student

where sno in(

select sno

from sc

where cno=1)[/code]

(2)查询“数据库”成绩在80分以上的学生的学号和姓名;

[code]Select sno,sname

From student

Where sno in(

select sno

from course,sc

where course.cno=sc.cno and course.cname=’数据库’ and grade>=80)[/code](3)查询计算机系最高成绩。

[code]select top 1 grade

from student,sc

where student.sno=sc.sno and sdept=’CS’

order by grade desc[/code]

3、查询同时选修了1号和2号课程的学生学号

[code]select sno

from sc

where cno=1 and sno in(

select sno

from sc

where cno=2)[/code]

4、查询选修了“离散数学”的学生姓名(连接查询)

[code]select sname

from student

where sno in(

select sno

from course,sc

where course.cno=sc.cno and course.cname=’离散数学’)[/code]

5、查询选修课程名为“数据库”的学生姓名(子查询)

[code]select sname

from student

where sno in(

select sno

from course,sc

where course.cno=sc.cno and course.cname=’数据库’)[/code]

6、查询与张天和张琪在同一个系的学生

[code]select *

from student

where sdept in(

select sdept

from student

where sname=’张天’ or sname=’张琪’)[/code]

查询与张天或张琪不在同一个系的学生

[code]select *

from student

where sdept not in(

select sdept

from student

where sname=’张天’ or sname=’张琪’)[/code]

7、查询比信息系所有学生年龄大的学生姓名

[code]select sname

from student s1

where s1.sage>all(

select sage

from student s2

where s2.sdept=’CS’)[/code]

8、查询比张天平均成绩高的学生姓名

[code]select sname

from student

where student.sno in(

select sno

from sc

group by sno

having avg(grade) >(

select avg(grade) as avg_grade2

from sc sc2,student

where student.sno=sc2.sno and sname=’刘晨’

group by sc2.sno)

)[/code]9、查询比学号为200215121学生年龄大的学生

[code]select *

from student s1

where s1.sage>(

select sage

from student s2

where s2.sno=’200215121′)[/code]

10、查询各系总分最高的学生学号

[code]Select sdept,student.sno

from student,sc

where student.sno=sc.sno

group by sdept,student.sno

having sum(grade)>=all(

select sum(grade)

from student,sc

where student.sno=sc.sno and sdept=student.sdept

group by student.sno)[/code]

11、查询选修了以6号课程为先行课的所有课程的学生学号。

[code]select distinct sno

from sc

where sc.cno in(

select cno

from course

where cpno=6)[/code]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169407.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 机器学习:回归问题

    机器学习:回归问题回归,我第一次看到回归的时候,想的就是回归是什么意思?后来看了一个答案解释很有意思,回归这个词来自于生物学,在调查父母与子代身高问题的时候,发现父母如果过高的话,子女就会比父母矮一点,如果父母矮的话,

    2022年8月6日
    5
  • DOS命令:copy

    DOS命令:copycopy命令,将至少一个文件复制到另一个位置copy/?—查看官方帮助文档对COPYT的解释说明COPY[/D[1]][/V][/N][/Y|/-Y][/Z][/A|/B]source[/A|/B][+source[/A|/B][+…]][destination[/A|/B]]source指定要复制的文件。/A表示一个ASCII文本文件。/B表示一个二进位文件。/D允许解密要创建的目标文件dest…

    2022年7月18日
    14
  • 二叉树性质[通俗易懂]

    二叉树性质[通俗易懂]转载skywang12345 http://www.cnblogs.com/skywang12345/p/3576328.html树的介绍1.树的定义树是一种数据结构,它是由n(n>=1)个有限节点组成一个具有层次关系的集合。把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它具有以下的特点:(01)每个节点有零个或多个子

    2022年5月31日
    34
  • java中数组的输出方法_java将一个数组逆序输出

    java中数组的输出方法_java将一个数组逆序输出%d:以十进制的形式输出带符号的整数。%o:以八进制的形式输出无符号的整数。%x:以十六进制的形式输出无符号整数。%u:yishijinzhid

    2022年10月11日
    0
  • 利用ffmpeg制作gif图[通俗易懂]

    利用ffmpeg制作gif图[通俗易懂]由于老师安排的作业有需求,这里就记录一下利用ffmpeg制作gif图1.确保ffmpeg安装运行会显示版本号:ffmpeg-version没有安装的话先安装:sudoapt-repositoryppa:kirillshkrogalev/ffmpeg-nextsudoapt-getupdatesudoapt-getinstallffmpegffmpeg-ve…

    2025年6月26日
    0
  • 回溯递归算法—-八皇后问题

    回溯递归算法—-八皇后问题

    2022年1月2日
    37

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号