Student(S#,Sname,Sage,Ssex) 学生表 
Course(C#,Cname,T#) 课程表 
SC(S#,C#,score) 成绩表 
Teacher(T#, Tname) 教师表 
注:#代主键 
1.查询“001”课程比“002”课程成绩高的所有学生的学号; 
2.查询各科成绩前三名的记录:(不考虑成绩并列情况) 
3.把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;
4.查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名
5. 用二种方法删除“教师表”所有的记录好久没有用过数据库了
很多东西都忘得差不多了
请各位高手们帮帮们

解决方案 »

  1.   

    1. select a.s# from sc a , sc b where a.c#='001' and b.c#='002' and a.s#=b.s# and a.score>b.score
      

  2.   

    2  
    select * from (
    select s#,c#,score ,dense_rank() over(partition by C# order by  score desc ) num  from  sc) t 
    where t.num<=3
      

  3.   

    Student(S#,Sname,Sage,Ssex) 学生表 
    Course(C#,Cname,T#) 课程表 
    SC(S#,C#,score) 成绩表 
    Teacher(T#, Tname) 教师表 update sc t set t.score=( select score from (select a.c# ,avg(b.score) score from course a ,sc b ,techer c where a.c#=b.c# and a.t#=c.t# and c.tname='张平' gruop by a.c# ) s where t.c#=s.c# )
      

  4.   

    5 delete * from techer;
      truncate table techer;