首页 > 试题广场 >

已知关系模式: Student(S#,Sname,Sa

[问答题]

已知关系模式:

Student(S#,Sname,Sage,Ssex) 学生表,

Course(C#,Cname,T#) 课程表,

SC(S#,C#,score) 成绩表,

Teacher(T#,Tname) 教师表 。

其中,S#代表学生号,C#代表课程号,T#代表教师号。

根据上述描述,请写出如下的查询语句:

1、查询“001”课程比“002”课程成绩高的所有学生的学号;
2、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;
3、查询每门功成绩最好的前两名
1.

select * from SC s1, SC s2 where s1.S# = s2.S# and s1.C# = '001' and s2.C# = '002 and s1.score > s2.score

2. 
select distinct S.S#,S.Sname from S,SC where C# in (select C# from SC where S# = "1001") and S.S# = SC.S#
3.
select m.* , n.C# , n.score from Student m, SC n where m.S# = n.S# and n.score in
(select top 3 score from sc where C# = n.C# order by score desc) order by n.C# , n.score desc
发表于 2019-08-18 20:19:32 回复(0)
3、
select * from ( select S#,C#,score ,row_number() over (partition by C# order by score desc) as rank from SC ) a where a.rank <3
发表于 2022-07-15 22:35:19 回复(1)