函数
小于 1 分钟约 237 字
日期

获取当前系统时间
select curtime()
获取年月日
select year(curdate())
select month(curdate())
select day(curdate())
获取一年中的第几周
select week(now())
获取学生的生日日期(不需要年)
select month(birthday), day(birthday) from student
判断函数
case
when 条件表达式1 then 表达式2
when 条件表达式3 then 表达式4
else '其他'
end
字符串函数
获取字符串长度
select char_length('length')
拼接字符串
select concat(month(birthday),'月',day(birthday),'日') as '生日' from student
转大写、小写
select lower('Test')
select upper('Test')
截取字符串
select substr('Test',1,3)
去除字符串前后空格
select trim(' Te st ')
中间空格不会去掉
数学函数
获取随机数字
select rand()
四舍五入
select round('3.1415926',4)
截取数字
select truncate('3.1415926',4)
获取最小值
select least(11,2,4,7,19,2)