当前位置:   article > 正文

【数据库原理及应用 - 作业】单表查询与多表查询练习_查询哪些学生没有选课,要求列出学号

查询哪些学生没有选课,要求列出学号

注意:Sno、Cno是主键

一、单表查询联系作业

1.1、查询选课表中全部数据

select * from SC
  • 1

1.2、查询计算机系学生的学号、姓名和所在系部

select Sno, Sname, Sdept from Student
  • 1

1.3、查询数学系年龄在18~22之间性别为“男”的学生的姓名和年龄

select Sname, Sage 
from Student 
where Sdept='数学' and Ssex='男' and Sage BETWEEN 18 AND 22
  • 1
  • 2
  • 3

1.4、查询C01号课程的最低分

select min(Grade) from SC where Cno='C01'
  • 1

1.5、统计每个系的学生人数

select Sdept, count(*) from Student group by Sdept
  • 1

1.6、查询在计算机学院的女学生

select * from Student where Ssex='女' and Sdept='计算机'
  • 1

1.7、查询学生表有多少行记录

select count(*) from Student
  • 1

二、多表查询练习作业

2.1、查询选修了“C02”号课程的学生的姓名和所在系

select Sname, Sdept from Student, SC where Student.Sno=SC.Sno and SC.Cno='C02'
  • 1

2.2、查询成绩在80分以上的学生的姓名、课程号和成绩,并按成绩降序排序

select Sname, Smajor, Grade 
from Student, SC
where Student.Sno=SC.Sno and Grade>80 order by Grade DESC
  • 1
  • 2
  • 3

2.3、查询哪些学生没有选课,要求列出学号、姓名和所在系

select Sno, Sname, Sdept from Student, SC where Sno NOT IN(
    select Sno from SC
)
  • 1
  • 2
  • 3

2.4、用子查询实现如下查询

2.4.1、查询选修了“C01”号课程的学生姓名和所在系
select Sname, Sdept from Student, SC where Sno IN(
    select Sno from SC where Cno='C01'
)
  • 1
  • 2
  • 3
2.4.2、查询数学系成绩80分以上的学生的学号、姓名、课程号和成绩
select Sno, Sname, Cno, Grade from Student, SC where Sdept='数学' and Sno IN(
    select Sno from SC where Grade>80
)
  • 1
  • 2
  • 3
2.4.3、查询计算机系考试成绩最高的学生的姓名
select Sname from Student, SC where Sdept='计算机' and Sno IN(
    select Sno from SC where Grade IN(
        select Max(grade) from SC
    )
)
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/871514
推荐阅读
相关标签
  

闽ICP备14008679号