题目:
在SQL Server 数据库中,有一个表StudentAchievement(学生成绩),它有三个字段:StudentID(varchar(8),学生编号),CourseID(varchar(10),课程编号),Achievement(int ,成绩),写一条SQL语句,筛选出每门课程的前两名的学生编号,课程编号,成绩并排序
答案:
select a.* from StudentAchievement a where a.StudentID in (select top 2 StudentID from StudentAchievement where CourseID=a.CourseID order by Achievement desc)
答案:
select a.* from StudentAchievement a where a.StudentID in (select top 2 StudentID from StudentAchievement where CourseID=a.CourseID order by Achievement desc)