P46-P51
数学函数
1.round 四舍五入
select round(1.45) //1
select round(1.55) //2
select round(1.45678, 2) //1.46,表示保留两位小数
2.ceil 向上取整 floor向下取整
select ceil(1.0001) //2
select ceil(-1.0001) //-1
3 truncate 截断
select truncate(1.6666,1) //1.6
// 1表示小数点后保留几位数字
4 mod取余
select mod(10,3) // 1
select mod(-10,3) // -1
select mod(10,-3) // 1
// 取余结果跟第一个数的符号相同
日期函数
1.now() 获取当前日期+时间
select now() // 2020-12-6 22:27:30
curdate() 获取当前系统日期,不包括时间
select curdate() // 2020-12-6
curtime() 获取当前系统时间,不包括日期
select curdate() // 22:27:30
4.获取指定的部分,年、月、日、时、分、秒。
select year(now()) as 年// 2020 这里必须往里传个date类型
select year('1998-1-8') // 1998
select month(now()) as 月// 12
select monthname(now())// December
str_to_date 将字符串通过指定的格式转换成日期
image.png
select * from table where date = STR_TO_DATE('1-8 1998', '%c-%d %Y');
6 date_format 将日期转换成指定格式输出
select DATE_FORMAT(NOW(), '%Y年%m月%d日'); //2020年12月06日
其他函数
select version(); // 当前mysql的版本
select database(); // 当前数据库
select USER(); // 当前用户