這篇文章主要介紹MySQL中if else多條件的使用示例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
成都創新互聯公司專業為企業提供海西網站建設、海西做網站、海西網站設計、海西網站制作等企業網站建設、網頁設計與制作、海西企業網站模板建站服務,10余年海西做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
一、 編寫一條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多條件的使用示例”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創新互聯行業資訊頻道!