码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-26 11:34:46      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   2014   div   log   sp   on   

通过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

结果

bubuko.com,布布扣

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

标签:style   blog   http   color   2014   div   log   sp   on   

原文地址:http://www.cnblogs.com/syhsl/p/3936669.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!