diff --git "a/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/SQLQuery1.sql" "b/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..39e1a01b00d265b2366e0e9a0a0e3d27f9ecbfdf --- /dev/null +++ "b/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/SQLQuery1.sql" @@ -0,0 +1,39 @@ +--13. 按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 +select sc1.SId, +(select score from sc where cid='01' and sc.SId=sc1.sid) 语文, +(select score from sc where cid='02' and sc.SId=sc1.sid) 数学, +(select score from sc where cid='03' and sc.SId=sc1.sid) 英语, +AVG(score) 平均成绩 from sc sc1 +group by sid +order by AVG(score)desc +--要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列 +select sc.CId,c.Cname, +(select MAX(score) from sc group by cid having c.CId=sc.CId) 最高分, +(select MIN(score) from sc group by cid having c.CId=sc.CId) 最低分, +(select AVG(score) from sc group by cid having c.CId=sc.CId) 平均分, +((round(cast((sum(case when score >=60 then 1 else 0 end )) as float)/CAST(count(sc.cid) as float),2))*100) 及格率, +((round(cast((sum(case when score >=70 and score<=80 then 1 else 0 end )) as float)/CAST(count(sc.cid) as float),2))*100) 中等率, +((round(cast((sum(case when score >=80 and score<=90 then 1 else 0 end )) as float)/CAST(count(sc.cid) as float),2))*100) 优良率, +((round(cast((sum(case when score >=90 then 1 else 0 end )) as float)/CAST(count(sc.cid) as float),2))*100) 优秀率 +from Course c +inner join sc on sc.CId=c.CId +group by sc.CId,c.Cname,c.cid + +--15. 按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺 +select *,RANK() over (partition by cid order by score desc) rank from sc +--15.1 按各科成绩进行排序,并显示排名, Score 重复时合并名次 +select *,DENSE_RANK() over (partition by cid order by score desc) rank from sc +--16. 查询学生的总成绩,并进行排名,总分重复时保留名次空缺 +select s1.SId,(select Sname from Student where Student.sid=s1.SId) 姓名, +(select score from sc where cid='01' and sc.SId=sc1.sid) 语文, +(select score from sc where cid='02' and sc.SId=sc1.sid) 数学, +(select score from sc where cid='03' and sc.SId=sc1.sid) 英语, +sum(score) 总成绩, RANK() over (order by sum(score) desc) rank from sc sc1 +group by sid +--16.1 查询学生的总成绩,并进行排名,总分重复时不保留名次空缺 +select sc1.SId,(select Sname from Student where Student.sid=sc1.SId) 姓名, +(select score from sc where cid='01' and sc.SId=sc1.sid) 语文, +(select score from sc where cid='02' and sc.SId=sc1.sid) 数学, +(select score from sc where cid='03' and sc.SId=sc1.sid) 英语, +sum(score) 总成绩, DENSE_RANK() over (order by sum(score) desc) rank from sc sc1 +group by sid \ No newline at end of file diff --git "a/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/\346\216\222\345\272\217\357\274\214\345\205\263\350\201\224\345\255\220\346\237\245\350\257\242.txt" "b/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/\346\216\222\345\272\217\357\274\214\345\205\263\350\201\224\345\255\220\346\237\245\350\257\242.txt" new file mode 100644 index 0000000000000000000000000000000000000000..63b077e672323a408a7d5ea4db3d27dd5e9c3b70 --- /dev/null +++ "b/\350\260\242\351\207\221\351\207\221/\350\260\242\351\207\221\351\207\221\347\254\254\345\233\233\346\254\241\347\254\224\350\256\260\344\275\234\344\270\232/\346\216\222\345\272\217\357\274\214\345\205\263\350\201\224\345\255\220\346\237\245\350\257\242.txt" @@ -0,0 +1,18 @@ +淇濈暀绌虹己 +RANK() over (partition by ** order by ** desc) rank +涓嶄繚鐣欑┖缂 +DENSE_RANK() over (partition by ** order by ** desc) rank +鍏宠仈瀛愭煡璇 +-- 鎵鏈変粠鏉ユ病鏈変笅杩囧崟鐨勫鎴风殑淇℃伅 +select c_custkey +from + customer +where + not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) \ No newline at end of file