diff --git "a/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/.keep" "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/test.sql" "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/test.sql" new file mode 100644 index 0000000000000000000000000000000000000000..eed3433d9a1160b71a9e0d7a5629ada9761e0770 --- /dev/null +++ "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/test.sql" @@ -0,0 +1,71 @@ +--13. 按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 +select sc.SId,c.Cname,score,t.平均分 from sc +inner join Course c on c.cid = sc.CId +inner join +( +select sid,avg(score)平均分 from sc +group by sid +) t +on t.SId = sc.sid + +order by t.平均分 desc +--14. 查询各科成绩最高分、最低分和平均分: +--以如下形式显示:课程 ID,课程 name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 +--及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90 +--要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列 +select sc.CId,c.Cname, +(select max(score) from sc sc1 where sc.CId = sc1.CId)最高分, +(select min(score) from sc sc1 where sc.CId = sc1.CId)最低分, +convert(decimal(5,2),(select avg(score) from sc sc1 where sc.cid = sc1.cid))平均分, +concat(convert(decimal(5,2),(select (count(*)*100)/1.0/(select count(*) from sc sc3 where sc3.cid = sc.cid ) from sc sc2 where sc.cid = sc2.cid and sc2.score >= 60)),'%') 及格率, +concat(convert(decimal(5,2),(select (count(*)*100)/1.0/(select count(*) from sc sc3 where sc3.cid = sc.cid ) from sc sc2 where sc.cid = sc2.cid and sc2.score between 70 and 80)),'%') 中等率, +concat(convert(decimal(5,2),(select (count(*)*100)/1.0/(select count(*) from sc sc3 where sc3.cid = sc.cid ) from sc sc2 where sc.cid = sc2.cid and sc2.score between 80 and 90)),'%') 优良率, +concat(convert(decimal(5,2),(select (count(*)*100)/1.0/(select count(*) from sc sc3 where sc3.cid = sc.cid ) from sc sc2 where sc.cid = sc2.cid and sc2.score >= 90)),'%') 优秀率 +from sc +inner join Course c +on c.CId = sc.CId +group by sc.CId,c.Cname + + +--15. 按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺 +select s.sid,sname,t1.语文排名,t2.数学排名,t3.英语排名 from student s +left join +( +select sid,rank() over(order by score desc) 语文排名 from sc where cid = '01' +) t1 on t1.sid = s.sid +inner join +( +select sid,rank() over(order by score desc) 数学排名 from sc where cid = '02' +) t2 on t2.sid = s.sid +left join +( +select sid,rank() over(order by score desc) 英语排名 from sc where cid = '03' +) t3 on t3.sid = s.sid +--15.1 按各科成绩进行排序,并显示排名, Score 重复时合并名次 +select s.sid,sname,t1.语文排名,t2.数学排名,t3.英语排名 from student s +left join +( +select sid,dense_rank() over(order by score desc) 语文排名 from sc where cid = '01' +) t1 on t1.sid = s.sid +inner join +( +select sid,dense_rank() over(order by score desc) 数学排名 from sc where cid = '02' +) t2 on t2.sid = s.sid +left join +( +select sid,dense_rank() over(order by score desc) 英语排名 from sc where cid = '03' +) t3 on t3.sid = s.sid +--16. 查询学生的总成绩,并进行排名,总分重复时保留名次空缺 +select t.SId,t.总分,dense_rank() over (order by 总分 desc) 排名 +from +( +select sid,sum(score) 总分 from sc +group by sid +) t +--16.1 查询学生的总成绩,并进行排名,总分重复时不保留名次空缺 +select t.SId,t.总分,rank() over (order by 总分 desc) 排名 +from +( +select sid,sum(score) 总分 from sc +group by sid +) t \ No newline at end of file diff --git "a/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/2022-9-21-\347\252\227\345\217\243\346\216\222\345\210\227\345\207\275\346\225\260.md" "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/2022-9-21-\347\252\227\345\217\243\346\216\222\345\210\227\345\207\275\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..07ce4e4f9398b056c5c4c95ee8f7790663c304af --- /dev/null +++ "b/22 \346\235\250\345\207\214\347\277\224/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/2022-9-21-\347\252\227\345\217\243\346\216\222\345\210\227\345\207\275\346\225\260.md" @@ -0,0 +1,3 @@ +--Rank , ռλ +--DENSE_RANK , ռλ +--ROW_NUMBER , ռλ \ No newline at end of file