Home > Database > Mysql Tutorial > mysql if else multiple conditions

mysql if else multiple conditions

(*-*)浩
Release: 2019-05-17 19:00:46
Original
28929 people have browsed it

MySQL How to use a statement to achieve judgment similar to if-else conditional statements

mysql if else multiple conditions

1. Write an update statement to achieve product price increase. The specific rules are as follows

1. Within 99 yuan, the price will be increased by 20%

2. Between 100-999 yuan, the price will be increased by 10%

3. Between 1000-1999 During the period, the price will be increased by 5%

4, and other prices will be increased by 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;
Copy after login

2. Write a select statement to achieve the following effect

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

Rules As follows:

1, >=90: Excellent

2, >=80: Good

3, >=60: Pass

4. <60: Failed

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;

The above is the detailed content of mysql if else multiple conditions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template