对于教学数据库的三个基本表: S(S#,SNAME,AGE,SEX) SC(S#,C#,GRADE) C(C#,CNAME,TEACHER) 试用SQL的查询语句表达下列查询: 1)检索LIU老师所讲授课程的课程名。 2)检索年龄大于19岁的男学生的学号和姓名。 3)检索学号为S1的学生的姓名及所学课程的课程名。 4)检索SUN同学不学的课程的课程号。 5)统计每门课程的学生选修人数(超过10人的课程才统计)。要求显示课程号和人数,查询结果按人数降序排列,若人数相同,按课程号升序排列。 6)求LIU老师所授课程的每门课程的平均成绩。 7)求年龄大于女同学平均年龄的男学生姓名和年龄。 8)检索姓名以L打头的所有学生的姓名和性别。 9)把低于所有课程总平均成绩的女同学成绩提高5%。 10)在SC中删除尚无成绩的选课元组。
1)select cname from c where teacher=’liu’ 2)select s#,sname from student where age>19 and sex=’男’ 3)select sname,cname from sc,c,s where s.s#=sc.s# and sc.c#=c.c# and s#=’s1’ 4)select c# from c where c# not in (select c# from s,sc where s.s#=sc.s# and sname=’SUN’) 5)select c#,count(*) from sc group by c# having count(*)>=10 order by 2 desc,1 asc 6)select c#,avg(grade) from sc,c where c.c#=sc.c# and teacher=’LIU’group by c.c# 7)select sname,age from s where age>(select avg(age) from s where sex=’女’) 8)select sname,sex from s where sname like ‘L%’ 9) update sc set grade=grade+grade*5% where s# in (select s# from sc,s where sc.s#=s.s# and grade<(select avg(grade) from sc)) 10)delete from sc where grade is null