mysql流程控制

if 函数

select if(2>1, '是2','是1') 字段;
+--------+
| 字段   |
+--------+
| 是2    |
+--------+
1 row in set (0.00 sec)

case 语句

select age,
case age
when 18 then '今年成年'
when 30 then '今年30岁'
when 40 then '今年40岁'
else age
end as 新字段
from student;
+------+--------------+
| age  | 新字段       |
+------+--------------+
|   18 | 今年成年     |
|   20 | 20           |
|   20 | 20           |
|   23 | 23           |
|   19 | 19           |
|   18 | 今年成年     |
|   30 | 今年30岁     |
+------+--------------+
7 rows in set (0.03 sec)
posted @ 2021-07-08 10:26  胡勇健  阅读(32)  评论(0)    收藏  举报