数学函数
#round 四舍五入
不管正负数
select round(1.65); --->2
select round(1.567,2): --->1.57 第二个参数意思是保留小数点后两位
#ceil 向上取整
select ceil(1.2) -->2
#floor 向下取整
select floor(1.6) -->1
#truncate 截断
select truncate(1.699,1) --->1.6 小数点后 保留几位
#mod 取余
select mod(10,3) --->1
和百分号一样的%
日期函数
# now 返回当前系统日期加时间
select now();
#curdate 返回当前系统日期,不包括时间
select cudate();
#curtime 返回当前时间 , 不包括日期
select curtime();
#获取指定的部分 年 月 日 小时 分钟 秒
select year(now()) as 年;
#str_to_date 将字符通过指定的格式转换成日期
select str_to_date('1998-3-2','%Y-%c-%d') as out_put;
#date_format 将日期转换成字符
select date_format(now(),'%y年%m月%d日') as out_put;
流程控制函数
#1. if函数
select if(10>5,'大','小') --->大
#2.case 函数 的使用一 : switch case的效果
语法
case 要判断的字段或表达式
when 常量1 then 要显示的值1或语句1;
when 常量2 then 要显示的值2或语句2;
…
else 要显示的值n或语句n;
end
#3.case 函数的使用二: 类似于 多重if
语法
case
when 条件1 then 要显示的值1或语句1; (值不加分号)
…
else要显示的值n或语句n
end