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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 9.29PMP每日一题

    9.29PMP每日一题

    2021年6月13日
    117
  • php allow_url_include,allow_url_include的应用和解释

    php allow_url_include,allow_url_include的应用和解释PHP常常因为它可能允许URLS被导入和执行语句被人们指责。事实上,这件事情并不是很让人感到惊奇,因为这是导致称为RemoteURLIncludevulnerabilities的php应用程序漏洞的最重要的原因之一。因为这个原因,许多安全研究人员建议在php.ini配置中禁用指向allow_url_fopen。不幸的是,许多推荐这种方法的人,并没有意识到,这样会破坏很多的应用并且并不能保证1…

    2022年7月21日
    12
  • linux重启tomcat进程,Linux系统重启tomcat服务的方法详解「建议收藏」

    Linux系统下tomcat服务的重启需要通过命令来解决。下面由学习啦小编为大家整理了Linux系统重启tomcat服务的方法详解,希望对大家有帮助!Linux系统重启tomcat服务的方法详解一在Linux系统下,重启Tomcat使用命令操作的!首先,进入Tomcat下的bin目录cd/usr/local/tomcat/bin使用Tomcat关闭命令./shutdown.sh查看Tomcat是…

    2022年4月7日
    92
  • linux中kill命令详解_linux kill函数

    linux中kill命令详解_linux kill函数linuxkill命令详解一、命令格式:kill[参数][进程号]二、命令功能:发送指定的信号到相应进程。不指定型号将发送SIGTERM(15)终止指定进程。如果任无法终止该程序可用“-KILL”参数,其发送的信号为SIGKILL(9),将强制结束进程,使用ps命令或者jobs命令可以查看进程号。root用户将影响用户的进程,非root用户只能影响自己的进程。三、命令参数:-l信号,若果不加信号的编号参数,则使用“-l”参数会列出全部的信号名称-a当处理当前进程时,不

    2025年7月1日
    4
  • 理解Object.defineProperty方法

    理解Object.defineProperty方法nbsp nbsp 之前没怎么对 Object defineProper 方法做深入了解 就知道可以通过这个方法可以设置对象的属性 现在稍微了解以后 发现还是有不少东西值得记录一下的 所以写下这篇博客 一 语法 Object defineProper obj prop descriptor nbsp nbsp nbsp nbsp obj 需要定义属性的对象 nbsp nbsp prop 需要定义的属性 nbsp nbsp descriptor 属性的描述描述符 nbsp

    2026年2月5日
    0
  • 零基础学Java(8)数组

    零基础学Java(8)数组数组数组存储相同类型值的序列。声明数组数组是一种数据结构,用来存储同一类型值的集合。通过一个整型下标(index,或称索引)可以访问数组中的每一个值。例如,如果a是一个整型数组,a[i]就是数组

    2022年7月29日
    8

发表回复

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

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