一.字符串函数
select concat('字符串一','字符串二');//字符串拼接
select lower('字符串');//字符串转小写
select upper('字符串');//字符串转大写
select trim(' 字符串 ');//去除前后空格,不去除中间空格
select substring('字符串','起始位置','长度');//字符串切片
select lpad('字符串',宽度,'填充字符');//向左填充
select rpad('字符串',宽度,'填充字符');//向右填充
字符串切片(字符串起始位置=1);
二.数值函数
select ceil(小数);//向上取整
select floor(小数);//向下取整
select mod(被除数,除数);//取余数
select rand();//随机生成0~1之间的小数
select round(小数,保留的位数);//四舍五入的规则
三.日期函数
select curdate();返回当前年月日 cur(current)当前的意思;
select curtime();返回当前时分秒;
select now();返回当前年月日时分秒;
select year(now());返回当前年份;
select month(now());返回当前月份;
select day(now());返回当前天;
select day_add('日期',interval 数字 类型);类型可以为(年,月,日)interval为时间间隔的意思;
select daydiff('日期一','日期二'); 返回日期一减日期二;
四.流程函数
select if(values,t,f);//如果values为true返回t,为false返回f;
select ifnull(值一,值二);如果值一不为空返回值一,为空返回值二;
select (case 字段 when 值一 then '改为..' when 值二 then '改为...' eles '改为...' end)[as] 别名 from 表名;
select (case when 字段比较值一 then '改为..' when 字段比较值二 then '改为...' eles '改为...' end)[as] '别名' from 表名;
//case 示例
select name,
id,
(case age when 18 then '年轻' when 17 then'漂亮' else '成熟' end) '颜值'
from student;
select name,
id,
(case when age<20 then '有活力' when age<30 then '有干劲' else '摆烂' end) '学习状态'
from student;