数据库学习第六天:case-end/when-then

2019-11-05  本文已影响0人  mapg
--成绩级别
select 数学成绩 = 
 case
   when tsenglish>100 then '优'
   when tsenglish>90 then '良'
   when tsendlish>80 then '中'
   when tsenglish>70 then '及格'
   when tsendlish is NULL then '缺考'
   else '不及格'
 end
 from tb_score

--识别论坛成员级别
 select *, 级别 =
 (
     case
     when leve=1 then '大侠'
     when leve=2 then '大侠'
     when leve=3 then '菜鸟'
     end
 ) 
 from tb_user

--比较数值大小
 select
 (

     case 
        when a>b then a else b
     end
 ),
 (
     case
      when b>c then b else c
     end
 )
 from tb_abc

--排列出销售人员的成绩排名
select 销售员,
       销售总金额=SUM(销售总量*市场价格),
       称号=
       (
         case
            when SUM(销售总量*市场价格)>1000 then '金牌'
            when SUM(销售总量*市场价格)>8000 then '银牌'
            when SUM(销售总量*市场价格)>5000 then '铜牌'
            else '优化名单人员'
         end
       )
from tb_myoeder
GROUP BY 销售员

上一篇下一篇

猜你喜欢

热点阅读