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月10日 上午10:16
下一篇 2022年8月10日 上午10:16


相关推荐

  • Nano-Banana小白教程:如何快速生成说明书风格设计图

    Nano-Banana小白教程:如何快速生成说明书风格设计图

    2026年3月13日
    1
  • 【221页干货】一文读懂AI智能体和代理式AI

    【221页干货】一文读懂AI智能体和代理式AI

    2026年3月15日
    2
  • 闰年算法

    闰年算法summary 返回月份拥有的天数 summary paramname month paramname year returns returns p paramname year paramname month

    2026年3月19日
    3
  • SIP服务器类型

    SIP服务器类型有一些不同类型的 SIP 服务器 根据你的应用 你可以使用它们其中的一种或所有类型来解决你的问题 OpenSIPS 可以作为代理服务器 重定向服务器 背靠背用户代理或者注册服务器 Theproxyserv 代理服务器 在 SIP 代理模式下 所有的 IP 消息都要经过 SIP 代理 这种行为在向诸如计费 billing 的过程中帮助很大 而且迄今为止 这也是一种最普遍的选择 但是它的缺点就是在会

    2026年3月19日
    2
  • java输入语句怎么写_java输入语句应该怎样写?示例演示

    java输入语句怎么写_java输入语句应该怎样写?示例演示作为初步进入java开发学习的小白来说,就像是小时候刚刚学说话一样,这种经历既是必然的也是有趣的,学习java语言一开始的时候也是得一步步的学习,比如说,java输入语句应该这么去实现呢?一起跟小编来看看吧。第一步:导包。先将java.io.*;以及java.util.*;导入Java代码中。charc=(char)System.in.read();是输入单个字符;inta=cin.nextI…

    2022年7月9日
    36
  • 每天一道算法_4_Hangover

    此系列刚开始两天就被十一假期打断了,去山西玩了几天,今天刚回来,为了弥补一下心里的貌似隐隐作痛的愧疚感,补上一刀。今天的题目是 Hangover,如下: DescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a max

    2022年3月10日
    36

发表回复

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

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