温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql中if else多条件的使用示例

发布时间:2020-12-01 11:50:31 来源:亿速云 阅读:1518 作者:小新 栏目:MySQL数据库

这篇文章主要介绍mysql中if else多条件的使用示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

一、 编写一条update语句实现商品涨价,具体规则如下

1、99元以内,提价20%

2、100-999元之间,提价10%

3、1000-1999之间,提价5%

4、其他提价2%

update goods  
set price = (  
case   
  when price between 0 and 99 then price * 1.2  
  when price between 100 and 999 then price * 1.1  
  when price between 1000 and 1999 then price * 1.05  
  when price > 1999 then price * 1.02  
end);  
select * from goods;

二、 编写一条select语句,实现如下效果

 学号   姓名 分数 等级
-------------------------------------------------
 1       张三   86   良好
 2       李四   98   优秀
 3       王五   72   及格
 4       那六   69   及格
 5       小幺   56   不及格

规则如下:

1、>=90:优秀

2、>=80:良好

3、>=60:及格

4、<60:不及格

select id as 学号, name as 姓名, score as 分数,   
(  
  case   
    when score >= 90 then '优秀'  
    when score >= 80 and score < 90 then '良好'  
    when score >= 60 and score < 80 then '及格'  
    when score < 60 then '不及格'  
  end  
)  
as 等级  
from scores;

以上是“mysql中if else多条件的使用示例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI