From b072814ef1d45a02badeb0e4ec937d2e6bd575dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E9=87=91=E9=87=91?= <1665966989@qq.com> Date: Thu, 22 Sep 2022 04:43:16 +0000 Subject: [PATCH] =?UTF-8?q?=E8=B0=A2=E9=87=91=E9=87=914?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谢金金 <1665966989@qq.com> --- .../SQLQuery1.sql" | 39 +++++++++++++++++++ ...4\345\255\220\346\237\245\350\257\242.txt" | 18 +++++++++ 2 files changed, 57 insertions(+) create mode 100644 "\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" create mode 100644 "\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" 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 0000000..39e1a01 --- /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. ƽɼӸߵʾѧпγ̵ijɼԼƽɼ +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 0000000..63b077e --- /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 -- Gitee