字符函数
- legth(str) 获取参数值的字节个数
- concat(str1,str2,…) 拼接字符串
- upper(str) 转大写
- lower(str) 转小写
- substr(str,startI) 从start开始截取
- substr(str,start,end) 从start开始截取到end结束,包括end
- instr(source,target) 返回了target子串在source中第一次出现的索引
- trim(str) 去前后空格
- trim(key from str) 去除str前后的key子串
- lpad(str,length,fill) 指定fill子串填充到str左边直到总长度为length
- rpad(str,length,fill) 指定fill子串填充到str右边直到总长度为length
- replace(str,fromStr,toStr) 将fromStr替换为toStr
数学函数
round() 四舍五入
ceil() 向上取整
floor() 向下取整
truncate() 截断
mod() 取余
日期函数
now() 返回当前系统日期+时间
curdate() 返回当前系统日期
curtime() 返回当前系统时间
str_to_date(str,format)
str_to_date(‘1995-01-01’,’%Y-%m-%d’)
date_format(date,format)
date_format(‘1995-01-01’,’%Y-%m-%d’) date_format(now(),’%Y-%m-%d’)
datediff(date1,date2) 相差天数
流程控制函数
if(判断条件,是结果,否结果)
case 要判断的字段或表达式
when 常量 then 要显示的值或语句
…
else 默认的值或语句
end
case
when 条件 then 要显示的值或语句
…
else 默认的值或语句
end
聚合函数
sum
avg
min
max
count
都会忽略null
