嵌套查询练习

--1. 查询 “计算机 系”的班级信息。

select *from Class where DepartmentID=(select DepartmentID from Department where DepartmentName='计算机系')

--2. 查询“计算机系”的全部学生信息。

select *from Student

inner join Class on Class.ClassID=Student.ClassID

where Class.DepartmentID=(select DepartmentID from Department where DepartmentName='计算机系')

--3. 查询Dp010001课程中成绩未达到该门课程平均分的选课信息。

select *from Course

inner join Grade on Course.CourseID=Grade.CourseID

where Course.CourseID ='Dp010001' and Grade<(select avg(Grade) from Grade where CourseID='Dp010001')

--4. 查询Dp010001课程中最低分的学生信息。

select *from Student

inner join Grade on Student.StudentID=Grade.StudentID where Grade=(select min(Grade)from Grade where CourseID='Dp010001')

--5. 查询Cs010901班比Cs010902班年龄都大的学生信息。

select *from Student

where ClassID='Cs010901'and Birth <all(select Birth from Student where ClassID='Cs010902')

--6. 用带EXISTS子查询选修了Dp010001的学生学号和姓名

select StudentID,StudentName from Student where exists(select * from Course where CourseID='Dp010001')

--7. 查询course表中的最大学分和最小学分的课程名。

select CourseName from Course where credit =(select max(credit)  from Course) or credit=(select min(credit) from Course)

--8.查询选修了Dp010001课程而没有选修Dp010002号课程的学生学号。

select StudentID from Grade where CourseID='Dp010001'and CourseID!='Dp010002'

--9.查询计算机系选修了5门以上课程的学生的学号和姓名。

select Student.StudentID,StudentName from Student

inner join Grade on Grade.StudentID=Student.StudentID 

where exists(select DepartmentID from Department where DepartmentName='计算机系')

group by Student.StudentID,StudentName having count(Grade)>=5

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值