MySQL中CASE WHEN THEN用法

MySQL中CASE WHEN THEN用于分类统计

1、创建一个表
create table user(
    id int auto_increment primary key,
    age tinyint unsigned not null
);

2、添加一些数据

insert into user(age) values(12),(15),(20),(30),(35),(19),(24),(8),(61),(14);


3、CASE WHEN THEN
select id,age,(case when age<18 then '少年' when age>=18 then '成年' end) as type  from user;

猜你喜欢

转载自blog.csdn.net/u010071211/article/details/84780295
今日推荐