数值函数
ceil(x): 返回大于x的最小整数值 select ceil(28.5); 结果:29
floor(x):返回小于x的最小整数值 select floor(28.5); 结果:28
round(x):四舍五入
round (x,y) 对x四舍五入,保留y位小数 select round(28.55,1); 结果:28.6
truncate(x,y) 截断函数,不四舍五入 select truncate(28.55,1); 结果:28.5
mod(x): 取余函数 select mod(11,2); 结果:1
字符函数
concat(s1,s2,..):链接函数 select concat('hello','world'); 结果:helloworld
concat_ws(x,s1,s2,...):分割函数 select concat_ws('-','hello','world'); 结果:hello-world
lower(str):大写字母转换为小写字母 select lower('HELLO'); 结果:hello
upper(str):小转大
length(str): 返回字符串长度 select length('hello'); 结果:5
ltrim(s):删除字符串左侧空格
rtrim(s):删除字符串右侧空格
substring(s,n,len):截取字符串 select substring('hellokkkk',1,5); 结果:hello
left(str,n):左截取字符串 select left('hello',2); 结果:he
right(str,n):右截取字符串
replace(str,a,b):替换函数 select replace('hello world','world','mysql'); 结果:hello mysql
format(x,n):将数字转换为字符串 并保留n位小数 select format(123.456,2); 结果:123.46
日期时间函数
curdate() select curdate(); 结果:2018-4-12
curtime() select curtime(); 结果:21:15:30
now() select now(); 结果:2018-4-12 21:15:30
select date_add('2018-4-12',interval 5 month); 结果:2018-9-12
聚合函数
avg() 求某列的平均数
count() 求某列的行数
max() 求某列的最大数
min() 求某列的最小数
sum() 求某列值的和
信息函数与加密函数
version() 返回当前mysql服务器版本的版本号
connection_id() 返回mysql服务器当前连接的次数,每个连接都有各自唯一的id
database()和schema() 返回当前数据库名
user() 获取用户名的函数,返回当前登录用户的用户名
md5(str) 信息摘要算法,函数可以加密字符串 ,加密后的32位十六进制数字的二进制字符串形式返回,若参数为null,返回
null
password(str) 密码算法,从原明文密码str计算并返回加密后的密码字符串,当参数是null是,返回null