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]

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • sql server 2012 报表开发(2) reporting service 中制作分组折叠式报表

    sql server 2012 报表开发(2) reporting service 中制作分组折叠式报表前面我们学习了sqlserver2012如何使用ReportingService2012制作报表,对ReportingService制作报表,有了初步的了解,这里我主要记录一下,如何做一个分组折叠式的报表.1. 创建一个报表tb_Bills.rdl,添加一个数据集2.在当前报表中,添加一个列表3.在当前列表中,添加一个父组。选择需要分组字段的分组依据,

    2022年10月20日
  • 图像处理入门必看

    图像处理入门必看(原MyBlog)前要说明这段时间在网上找资料学习图像处理的相关知识,在网上看到这篇写得相当不错的文章,在大牛允许转载的情况下,特搬家至此,方便更多的初学者能够看到。正文开始最近有人问我图像处理怎么研究,怎么入门,怎么应用,我竟一时语塞。仔细想想,自己也搞了两年图像方面的研究,做个两个创新项目,发过两篇论文,也算是有点心得,于是总结总结和大家分享,希望能对大家有所帮助。在写这篇教程之前我本想多弄点插

  • c++常量和常量表达式[通俗易懂]

    c++常量和常量表达式[通俗易懂]const,默认情况下仅在文件内有效constinti(12);const引用:对常量的引用不能被用作修改它所绑定的对象constintci(5);constint&rci(ci);rci=90;//错误不能修改允许常量引用绑定到非常量的对象、字面值或表达式上inti=20;constint&ri(20);con…

  • 京东云服务器_docker 京东自动签到

    京东云服务器_docker 京东自动签到众所周知,京东的京豆可以在付款时抵扣现金支付,多攒京豆还是能省下一部分钱的,而且京豆的获取页很简单,其中一种就是通过签到的方式获得,而每天手动签到实在太过麻烦,如果能实现自动化就好了,这时,依靠于openwrt,京东自动签到插件就诞生了,在路由器上设置一下便可以一劳永逸,无需人工全部自动化完成,签到后可以自动将签到详细结果推送到手机的微信上,这种签到方式是在自己的路由器上,完全不用担心安全和隐私泄…

  • JLINK V9项目启动【jlink接口定义】【开启VCOM(虚拟串口)功能】「建议收藏」

    JLINK V9项目启动【jlink接口定义】【开启VCOM(虚拟串口)功能】「建议收藏」jlink接口定义摘录于:https://blog.csdn.net/u014124220/article/details/50829713仿真器端口 连接目标板 备注 1.VCC MCU电源VCC VCC 2.VCC MCU电源VCC VCC 3.TRST TRST Tes…

  • microsoft visual studio 2010 旗舰版的产品密

    microsoft visual studio 2010 旗舰版的产品密YCFHQ-9DWCY-DKV88-T2TMH-G7BHP

发表回复

您的电子邮箱地址不会被公开。

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