常见的流程函数:
代码:
select if(true,'OK','Error');/*如果第一个值为true,则返回OK,否则返回Error */select IFNULL(null,'default');/*如果第一个值为null,则返回default,否则返回第一个值 */
-- 查询emp表成员员工的姓名和工作地址(如果是北京/上海,则返回一线城市,否则返回二线城市)
select name,(case address when '北京' then '一线城市' when '上海' then '一线城市' else '二线城市' end) as '工作地址' from emp;
-- 查询班级里同学的id,姓名,和各项成绩(成绩>=85显示优秀,成绩>=60显示及格,成绩<60显示不及格)
create table score
(
id tinyint comment 'ID',
name varchar(20) comment '姓名',
math tinyint unsigned comment '数学',
english tinyint unsigned comment '英语',
chinese tinyint unsigned comment '语文'
)comment '成绩表';
insert into score (id, name, math, english, chinese) values (1,'张三',60,70,85),
(1,'李四',89,78,44),
(1,'王五',64,73,86),
(1,'老六',74,55,91),
(1,'老八',66,66,33);
select * from score;
select id,
name,
(case when math>=85 then '优秀' when math>=60 then '及格' else '不及格' end) as '数学',
(case when english>=85 then '优秀' when english>=60 then '及格' else '不及格' end) as '英语' ,
(case when chinese>=85 then '优秀' when chinese>=60 then '及格' else '不及格' end) as '语文'
from score; 标签:comment,函数,chinese,流程,when,60,select,85 From: https://www.cnblogs.com/123456dh/p/17293990.html