溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2020-12-01 11:50:31 來源:億速云 閱讀:1535 作者:小新 欄目:MySQL數(shù)據(jù)庫

這篇文章主要介紹mysql中if else多條件的使用示例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

一、 編寫一條update語句實現(xiàn)商品漲價,具體規(guī)則如下

1、99元以內(nèi),提價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語句,實現(xiàn)如下效果

 學號   姓名 分數(shù) 等級
-------------------------------------------------
 1       張三   86   良好
 2       李四   98   優(yōu)秀
 3       王五   72   及格
 4       那六   69   及格
 5       小幺   56   不及格

規(guī)則如下:

1、>=90:優(yōu)秀

2、>=80:良好

3、>=60:及格

4、<60:不及格

select id as 學號, name as 姓名, score as 分數(shù),   
(  
  case   
    when score >= 90 then '優(yōu)秀'  
    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多條件的使用示例”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI