问答题 存在如下表结构:
Student表结构
列名 含义 数据类型 约束
Sno 学号 普通编码定长字符串,长度为7 主码
Sname 姓名 普通编码定长字符串,长度为10 非空
Ssex 性别 普通编码定长字符串,长度为2 取值范围为:男,女
Sage 年龄 微整型 大于等于14
Sdept 所在系 普通编码不定长字符串,长度为20
Course表结构
列名 含义 数据类型 约束
Cno 课程号 普通编码定长字符串,长度为10 主码
Cname 课程名 普通编码不定长字符串,长度为20 非空
Periods 学时数 小整型 大于0
Porperty 课程性质 普通编码定长字符串,长度为4 取值范围为必须,选修
SC表结构
列名 含义 数据类型 约束
Sno 学号 普通编码定长字符串,长度为7 主码,引用Student的外码
Cno 课程号 普通编码定长字符串,长度为10 主码,引用Course的外码
Grade 成绩 小整型 取值范围为0~100
写出实现下述操作的SQL语句:

1.查询选课门数超过两门的学生的平均成绩和选课门数。
【正确答案】select sno,sum(grade)总成绩,avg(grade)平均成绩,count(*) 选课门数 from sc
group by sno having count(*)>2
【答案解析】
【正确答案】select sno,sum(grade) 总成绩 from sc
group by sno having sum(grade)>200
【答案解析】
【正确答案】select sname,sdept from Student join SC on Student.Sno=SC.Sno
where cno='C02'
【答案解析】
【正确答案】select sname,cno,grade
from student s join sc on s.sno=sc.sno
where grade>80
Order by grade desc
【答案解析】
【正确答案】select sname,ssex,grade
from student s join sc on s.sno=sc.sno
join course c on c.cno=sc.cno
where sdept='计算机系' and ssex='男'
and cname='数据库基础'
【答案解析】
【正确答案】select s.sno,sname,cno,grade from Student s left join SC
on s.Sno=SC.Sno
【答案解析】
【正确答案】select top 3 s.sno,sname,sdept,grade
from Student s join SC on s.Sno=SC.Sno
join Course c on c.Cno= SC.Cno
where cname='数据库基础'
order by grade desc
【答案解析】
【正确答案】select t1.sno,t2.sno,t1.cno
from sc as t1 join.sc as t2
on t1.cno=t2.cno
where tl.sno<t2.sno
【答案解析】
【正确答案】select c.cno,cname from course c left join sc
on c.cno=sc.cno
where sc.cno is null
【答案解析】
【正确答案】select sname,cname,grade
from student S join sc on s.sno=sc.sno
jom course c on c.cno=sc.cno
where sdept='计算机系'
and grade>(select avg(grade) from sc)
【答案解析】
【正确答案】select sname,sdept,grade
from student s join sc on s.sno=sc.sno
jom course C on c.cno=sc.cno
where grade=(
select min(grade) from sc
where cno in (
select cno from course where cname='vb'))
and cname='vb'
【答案解析】
【正确答案】select s.sno 学号,sname 姓名,
case sdept
when '计算机系' then 'CS'
when '信息系' then 'IS'
when '数学系' then 'MA'
else 'OTHER'
end as 所在系,grade 成绩
from student s join sc on s.sno=sc.sno
join course c on c.cno=sc.cno
where cname='vb'
【答案解析】
【正确答案】select c.cno,
case
when count(sc.cno)>100 then '人多'
when count(sc.cno) between 40 and 100 then'一般'
when count(c.cno)<40 then '较少'
when count(sc.cno)=0 then '无人选'
end as 选课人数
from sc right join course c on sc.cno=c.cno
group by c.cno
【答案解析】[解析] 本题考查的是SQL操作。