MySQL中CASE WHEN THEN用法

柔情只为你懂 2022-04-12 14:08 730阅读 0赞

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;

20181203215233870.png

发表评论

表情:
评论列表 (有 0 条评论,730人围观)

还没有评论,来说两句吧...

相关阅读