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


相关推荐

  • 简单工厂模式

    简单工厂模式

    2021年12月6日
    42
  • TTL232和RS232的区别

    逻辑电平定义不同:TTL232的0是用0v表示。1是用5V表示。RS232的0是用+3V–+15V表示,1是用-3V—15V表示。接口一般都用三根线,1:地线。2:写入。3:导出。他们不可直连,中间需接电平转接板,…

    2022年4月9日
    62
  • 国家信息中心数据恢复中心官网_stn源源

    国家信息中心数据恢复中心官网_stn源源写在前面:目前在学习pytorch官方文档的内容,以此来记录自己的学习过程,本次学习的是STN网络。传送门:官方文档中文翻译STN论文链接(SpatialTransformerNetworks)为什么要用到STN网络呢:卷积神经网络定义了一个异常强大的模型类,但在计算和参数有效的方式下仍然受限于对输入数据的空间不变性。在此引入了一个新的可学模块,空间变换网络,它显式地允许在网络中对数据进行空间变换操作。这个可微的模块可以插入到现有的卷积架构中,使神经网络能够主动地在空间上转换特征映射,在特征

    2022年10月9日
    2
  • getMessage(),getFile,getLine获取异常用法

    getMessage(),getFile,getLine获取异常用法

    2021年11月8日
    36
  • php测试工具_php单元测试

    php测试工具_php单元测试guzzle.png本文将介绍Guzzle,Guzzle在单元测试中的使用。来自Guzzle中文文档的解释:Guzzle是一个PHP的HTTP客户端,用来轻而易举地发送请求,并集成到我们的WEB服务上。接口简单:构建查询语句、POST请求、分流上传下载大文件、使用HTTPcookies、上传JSON数据等等。发送同步或异步的请求均使用相同的接口。使用PSR-7接口来请求、响应、分流,允许你使用其…

    2025年6月7日
    2
  • Python爬取豆瓣电影Top250并进行数据分析

    Python爬取豆瓣电影Top250并进行数据分析Python数据分析–豆瓣电影Top250利用Python爬取豆瓣电影TOP250并进行数据分析,对于众多爬虫爱好者,应该并不陌生。很多人都会以此作为第一个练手的小项目。当然这也多亏了豆瓣的包容,没有加以太多的反爬措施,对新手比较友好。版权声明:本文为博主原创文章,创作不易本文链接:数据爬取翻页操作第一页:https://movie.douban.com/top250第二页:https://movie.douban.com/top250?start=25&filter=第三页

    2022年6月1日
    58

发表回复

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

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