现有如下关系: 学生S(S#,SNMAE,AGE,SEX) 学习SC(S#,C#,GRADE) 课程C(C#,CNAME,TEACHER) 用SQL语言完成下列功能: 1)统计有学生选修的课程门数。 2)求选修C4课程的学生的平均年龄。 3)求李文老师所授课程的每门课程的学生平均成绩和最高成绩。 4)检索姓名以王打头的所有学生的姓名和年龄。 5)检索比“张三”年龄大的学生学号、姓名和年龄。 6)检索所有选修“C1”课程的学生学号、姓名及成绩,并将结果按成绩降序排列。 7)检索“李强”同学不学课程的课程号。 8)往基本表S中插入一个学生元组(’S9’,’WU’,18,’F’)。 9) 把低于总平均成绩的女同学的成绩提高10分。 10) 把王林同学的选课记录全部删除。
1)select count(distinct c#) from sc 2)select avg(age) from s where s# in (select s# from sc where c#=’c4’) 3)select c#,max(grade),min(grade) from sc,c where c.c#=sc.c# and teacher=’李文’group by c.c# 4)select sname,age from s where sname like ‘王%’ 5)select s#,sname,age from s where age>(select age from s where sname=’张三’) 6)select s#,sname,grade from s# in (select s# from sc where c#=’c1’) order by grade desc 7)select c# from c where c# not in (select c# from s,sc where s.s#=sc.s# and sname=’李强’) 8)insert into s values(’S9’,’WU’,18,’F’) 9) update sc set grade=grade+10 where s# in (select s# from sc where grade<(select avg(grade) from sc)) and sex=’女’ 10)delete from sc where s#=(select s# from s where sname=’王林’)