通过case when自定义的段位进行统计排序

通过case when 进行自定义排序

select * from (select a.c#,cname,case when score>=85 then '100-85'
                         when score<85 and score>=70 then '85-70'
                         when score<70 and score>=60 then '70-60'
                         else '0-60'
                         end 段位 
                         ,count(1) 数量
             ,count(1)*100.0/(select count(1)from sc where c#=a.c#) 均分
from sc a 
join course b on a.c#=b.c#
group by a.c#,cname,case when score>=85 then '100-85'
                         when score<85 and score>=70 then '85-70'
                         when score<70 and score>=60 then '70-60'
                         else '0-60'
                         end) a
order by  a.c#, case 段位 
                       when  '0-60' then 1
                       when  '70-60' then 2    
                       when  '85-70' then 3    
                       when  '100-85' then 4            
                  end

结果

posted @ 2014-08-26 10:31  起航Fly  阅读(463)  评论(0编辑  收藏  举报