首页 > 代码库 > 通过case when自定义的段位进行统计排序

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

结果

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