当前位置:网站首页>sql语句 练习题
sql语句 练习题
2022-06-28 15:06:00 【果董】
sql 语句练习题
看一看,你懂的!
1、查询学生的选课情况,要求显示学号、姓名、课程号
SELECT a.sno,a.sname,b.cno from dbo.student as a
right join dbo.sc as b on a.sno= b.sno
2、查询‘法学院’学生的修课情况,要求列出学生的名字、所修课的课程号和成绩。
select a.sname,b.cno,b.grade from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
where sdept='法学院'
3、查询''计算机科学学院''选修了‘数据库及应用’课程的学生的修课成绩,要求列出学生姓名、课程名和成绩。
select a.sname,c.cname,b.grade from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
inner join dbo.course as c on b.cno= c.cno
where a.sdept='计算机科学学院' and c.cname='数据库及应用'
4、查询所有修了‘军事理论’课程的学生的修课情况,要求列出学生姓名和所在的院系。(多表的连接)
select a.sname,a.sdept from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
inner join dbo.course as c on b.cno= c.cno
where c.cname='军事理论'
5、查询学生的修课情况,包括修了课程的学生和没有修课的学生,要求显示学号、姓名、课程号。
select a.sno,a.sname,b.cno from dbo.student as a
left join dbo.sc as b on a.sno = b.sno
left join dbo.course as c on b.cno= c.cno
6、查询哪些学生没有选课,要求列出学号、姓名和所在系。
select a.sno,a.sname,a.sdept from dbo.student as a
left join dbo.sc as b on a.sno = b.sno
left join dbo.course as c on b.cno= c.cno
where c.cname is null
7、用子查询查询与‘路飞’在同一个院系的学生的学号、姓名、院系。
select * from dbo.student as a
where a.sname !='路飞' and a.sdept in(select b.sdept from dbo.student as b where b.sname ='路飞')
8、用子查询找出平均成绩为大于80分的学生的学号、姓名、院系。
select s.sno,s.sname,s.sdept from dbo.student as s
where s.sno in (select b.sno from dbo.sc as b group by b.sno having avg(b.grade)>80 )
9、用子查询查询修了‘A008’课程且成绩高于此课程的平均成绩的学生所有数据。
select * from dbo.student as s
inner join dbo.sc as t on s.sno = t.sno
inner join dbo.course as c on t.cno=c.cno
where t.cno='A008'
and t.grade>(select avg(v.grade) from dbo.course as t
inner join dbo.sc as v on t.cno=v.cno
where t.cno='A008')
10、查询‘’医学院‘’考试成绩最高的学生的学号。
法一:
select top 1 a.sno,max(grade) from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
where a.sdept='医学院'
group by a.sno
order by max(grade)desc
法二:
select top 1 st.sno
from student st left join sc s on st.sno=s.sno where st.sdept='医学院'
order by s.grade desc
边栏推荐
- New offline retail stores take off against the trend, and consumption enthusiasm under the dark cloud of inflation
- R语言ggplot2可视化:使用patchwork包将两个ggplot2可视化结果纵向堆叠起来(stacking)形成组合图、一个可视化结果堆叠在另外一个可视化结果上
- dolphinscheduler2.X的安装(亲测有效)
- 张同学还没学会当主播
- The boss told me three times: low key, low key, low key
- 股票开户优惠链接,我如何才能得到?手机开户是安全么?
- 从五大能力到 “1+5+N”,华为让政企转型更稳健
- [C language] implementation of binary tree and three Traversals
- 新零售线下店逆势起飞,通膨乌云下的消费热情
- Vscode writes markdown file and generates pdf
猜你喜欢

The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)

vscode编写markdown文件并生成pdf

PMP真的有用吗?

New offline retail stores take off against the trend, and consumption enthusiasm under the dark cloud of inflation

币圈大地震:去年赚100万,今年亏500万

厨卫电器行业S2B2C系统网站解决方案:打造S2B2C平台全渠道商业系统

5000倍回报,南非报业投资腾讯赚了一个省

教育行业SaaS应用管理平台解决方案:助力企业实现经营、管理一体化

What is the renewal fee for PMP certificate?
![[spatial & single cellomics] phase 1: Study on PDAC tumor microenvironment by single cell binding spatial transcriptome](/img/c4/c053ec830a05f22cab7f7381f9f2b3.png)
[spatial & single cellomics] phase 1: Study on PDAC tumor microenvironment by single cell binding spatial transcriptome
随机推荐
[MySQL learning notes 23] index optimization
Q-Tester 3.2:适用于开发、生产和售后的诊断测试软件
Is PMP really useful?
WSUS客户端访问服务端异常报错-0x8024401f「建议收藏」
MIPS汇编语言学习-02-逻辑判断-前台输入
ROS知识点——ROS创建工作空间
猫狗图像数据集上的深度学习模型性能对比
The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)
The boss told me three times: low key, low key, low key
Combined sum leetcode
法兰克福地区目前支持sql了吗?
Facebook! Adaptive gradient defeats manual parameter adjustment
324. 摆动排序 II : 不简单的构造题
Not being a meta universe now is like not buying a house 20 years ago!
Express template engine
考了这个PMP证书到底有什么好处?
【mysql学习笔记24】索引设计原则
halcon 基础总结(一)裁切图片并旋转图像
Rails进阶——框架理论认知与构建方案建设(一)
R语言ggplot2可视化:使用patchwork包将3个ggplot2可视化结果自定义组合起来构成组合图、两个子图横向组合后和另外一个图纵向组合构成最终组合图