目录
函数
函数是指一段可以直接被另一段程序调用的程序或代码
字符串函数

数值函数

通过数据库的函数,生成一个六位数的随机验证码

日期函数





查询所有员工的入职天数,并根据入职天数倒序排序

流程函数
流程函数也是很常用的一类函数,可以在SQL语句中实现条件筛选,从而提高语句的效率


空字符串并不是null,所以返回是空字符串
查询emp表的员工姓名和工作地址(北京/上海 ---> 一线城市,其他 ----> 二线城市)


java
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 * from score;

需求:统计班级各个学员的成绩,如果大于等于85分,展示优秀,[60,85]展示及格,否则展示不及格
java
select id, 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;
