mysql case when
时间:2021-07-01 10:21:17
帮助过:3人阅读
a.*,
case
when a.age
= 1 then ‘一岁了‘
when a.age
= 2 then ‘二岁了‘
when a.age
>= 3 and a.age
<= 8 then (
case
when a.age
= 3 then ‘三岁了‘
when a.age
= 4 then ‘四岁了‘
when a.age
= 5 then ‘五岁了‘
when a.age
= 6 then ‘六岁了‘
when a.age
= 7 then ‘七岁了‘
when a.age
= 8 then ‘八岁了‘
end
)
when a.age
> 8 then ‘超过8岁了‘
end as agezh
from
users a;
同理when 条件也可以嵌套case when
mysql case when
标签: