select
name,
(case when (workaddress='北京' or workaddress = '上海') then '一线城市' else '二线城市' end) '工作地址'
from emp;
select name,if((workaddress='北京' or workaddress = '上海'),'一线城市','二线城市') '工作地址' from emp;
select
name,
(case when workaddress='北京' then '一线城市' when workaddress = '上海' then '一线城市' else '二线城市' end) '工作地址'
from emp;
☀ 统计各个学员的成绩
📢 >=85 优秀
📢 >= 60 及格
📢 <60 不及格
首先准备数据
sql复制代码
create table score(
id int comment 'ID',
name varchar(20) comment '姓名',
math int comment '数学',
english int comment '英语',
chinese int comment '语文'
) comment '学员成绩表';
insert into score(id, name, math, english, chinese) VALUES (1, 'Tom', 67, 88, 95
), (2, 'Rose' , 23, 66, 90),(3, 'Jack', 56, 98, 76);
select name,
(case when math >= 85 then '优秀' when math>=60 then '及格' else '不及格' end),
(case when english >= 85 then '优秀' when english>=60 then '及格' else '不及格' end ),
(case when chinese >= 85 then '优秀' when chinese>=60 then '及格' else '不及格' end)
from score;