mysql case when
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql case when相关的知识,希望对你有一定的参考价值。
select 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的主要内容,如果未能解决你的问题,请参考以下文章