SQL语句

10-1 查询没有选修’C语言’课程的学生 (10分)

select sno as 学号,sname as 姓名 from stu where not exists
(select * from sc where cno=( select cno from cou where cname = ‘C语言’) and stu.sno=sc.sno ) order by sno asc

10-2 查询S001学生选修而S003学生未选修的课程 (10分)

select distinct cno as 课程号 from sc where cno in(select cno from sc where sno=‘s001’)
and cno not in(select cno from sc where sno=‘s003’)

10-4 查询平均分高于80分的学生 (10分)

select sname from stu where sno in
(select sno from sc group by sno having avg(grade) > 80)

10-5 查询选修张老师讲授所有课程的学生 (10分)

select sname from stu where
not exists(select * from cou where not exists(select * from sc where stu.sno = sc.sno and sc.cno=cou.cno) and teacher=‘张老师’)

10-6 计算并填写学生获得的总学分 (10分)

UPDATE stu,(select sno,sum(credit) SUM
from(
select stu.sno sno,case when sc.grade>=60 then credit else NULL end credit
from stu left outer join sc on stu.sno=sc.sno left outer join cou on sc.cno=cou.cno
group by stu.sno,credit,grade) a
group by sno) B
SET stu.totalcredit = B.SUM
where stu.sno = B.sno

10-7 通过图书表和借阅表,查询图书的借阅情况,要求结果中包括以下几列:账号,条形码,书名和借书日期 (10分)

select 借阅.账号,借阅.条形码,图书.书名,借阅.借书日期 from 图书 join 借阅 on 图书.条形码=借阅.条形码

10-8 查询软件工程专业中年龄最大的同学姓名 (10分)

select distinct sname from stu join major on major.mno = stu.mno
where datediff( now(),stu.birdate ) in
(select max(datediff(now(),stu.birdate)) from stu join major on major.mno = stu.mno )
and major.mname = ‘软件工程’

10-9 查询选修了“C语言”课程,但是没有选修“数据结构”课程的学生 (10分)

select sname from stu where
sno in (select distinct sno from sc where
cno = (select cno from cou where cname =‘C语言’ ))
and sno not in (select distinct sno from sc where
cno = (select cno from cou where cname =‘数据结构’ ))

10-10 查询选修课程超过2门且成绩都在80分以上的学生 (10分)

select stu.sname as 姓名 , stu.mno as 专业,sum(cou.credit) as 总学分
from stu join major on stu.mno = major.mno join sc on stu.sno
=sc.sno join cou on cou.cno = sc.cno
where sc.grade >=80
group by sname,stu.mno having count(sc.cno)>=2

10-11 查询选修人数超过2人且成绩都在60分以上的课程 (10分)

select sc.cno as 课程号 ,cou.cname as 课程名,max(sc.grade) as
最高成绩,min(sc.grade) as 最低成绩, avg(sc.grade) as 平均成绩
from stu join major on stu.mno = major.mno join sc on stu.sno
=sc.sno join cou on cou.cno = sc.cno
where cname not in
(select distinct cname from sc join cou on sc.cno = cou.cno
where sc.grade is null ) and sc.grade>=60
group by sc.cno,cou.cname having count(sc.cno)>=2

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值