创建一个视图studentScore,查询学生的学号、姓名以及该同学所选修的所有课程的课程名和相应成绩,按学号(升序)、成绩(降序)排序输出。写出相应的SQL语句
create view studentScore
(studentNo,studentname,courseName,score)as
select S.studentNo,studentname,courseName,score from Student S
join Score on S.studentNo=Score.studentNo
join Course on Course.courseNo=Score.courseNo
go /*分割代码块,分别执行*/
/*视图是查询结果集,没有排序,所以需要另外做一个查询作排序*/
select * from studentScore order by studentNo,score desc
/*order by 后如果有多个排序条件,则依次*/
/*排序默认是升序。desc表示降序*/
结果:
Ps:升序是 ASC