SQL Server 学习

第一题 查询"103"课程不及格的学生学号,姓名和联系电话
select 学号,姓名,联系电话 from xsqk where 学号 in (select 学号 from xs_kc where 成绩<60 and 课程号='103')

第二题 查询恰有两门课程不及格的学生信息
select * from xsqk where 学号 in (select 学号 from xs_kc where 成绩<60 group by 学号 having COUNT(学号)=2)

第三题 查询每门课程最高分的学生记录
select * from xsqk where 学号 in (select b.学号 from (select 课程号,max(成绩) m from xs_kc GROUP BY 课程号) t,xs_kc b where t.课程号=b.课程号 and t.m=b.成绩)

select * from xs_kc a where 成绩= (select MAX(成绩) from xs_kc b where a.课程号=b.课程号)

第四题 查询每个学生的最低分学生记录
select * from xsqk where 学号 in (select b.学号 from (select 课程号,min(成绩) m from xs_kc GROUP BY 课程号) t,xs_kc b where t.课程号=b.课程号 and t.m=b.成绩)

select * from xs_kc a where 成绩= (select min(成绩) from xs_kc b where a.课程号=b.课程号)

第五题 查询每门课程的选修人数(提示:使用新增列完成)
select distinct a.课程号, 人数=(select COUNT(学号) from xs_kc b where b.课程号=a.课程号)from xs_kc a

select 课程号,count(学号) as 人数 from xs_kc group by 课程号

上一篇 拿来主义
下一篇 使用wordpress和宝塔面板搭建个人博客
ZYX

ZYX管理员

无论你遇见谁他都是你生命中该出现的 绝非偶然

本月创作热力图

2026年3月
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
加载中...
文章列表
1 HCIA-数据通信网络基础测一测
HCIA-数据通信网络基础测一测
2
阿里云Python学习实例
阿里云Python学习实例
3
js-typeof和变量强制类型转换
js-typeof和变量强制类型转换
4
SQL总知识点
SQL总知识点
5
C#-随机点名程序
C#-随机点名程序