Rank teacher sql

一段统计通过率的SQL

update pg set result=’通过’ where result=’修改通过’
select
    A.teacher,passCount,ISNULL(unPassCount,0) unPass,(passCount+ISNULL(unPassCount,0)) totalCount,(passCount*100/(passCount+ISNULL(unPassCount,0))) as pp
from(
select teacher,result,COUNT(1) passCount from pg  where RTRIM(result)=N’通过’  group by teacher,result
) A left join
(
select teacher,result,COUNT(1) unPassCount from pg  where RTRIM(result)=N’不通过’ group by teacher,result)
B  on RTRIM(A.teacher)=RTRIM(B.teacher) order by pp desc

第一句可以通过修改后面的sql去掉!

Leave a Reply