1. 程式人生 > >Oracle按各科平均成績從低到高和及格率的百分數從高到低排序

Oracle按各科平均成績從低到高和及格率的百分數從高到低排序

<pre name="code" class="sql">-- 按各科平均成績從低到高和及格率的百分數從高到低排序 
select sc.cid as 課程id,avg(sc.score) as 平均成績,
100*sum(case when sc.score>=60 then 1 else 0 end)/count(1)||'%' as 及格率
from sc
group by sc.cid
order by avg(sc.score),
sum(case when sc.score>=60 then 1 else 0 end)/count(1) desc;
<img src="https://img-blog.csdn.net/20161024224044767?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />