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)

浙公网安备 33010602011771号