聚集函数
avg()
count(age) 填了年龄的数量
max(age)
min(age)
sum(age)
select avg(age) as "年龄平均值" from student
where gender="male";
用于处理字符串的函数
合并字符串函数:concat(str1,str2,str3)
比较字符串大小函数:strcmp("a","b")
获取字符串字节数函数:length("abcd")
获取字符串字符数函数:char_length("abcd")
字母大小写转换函数:大写:upper("a"),ucase("x");
小写lower("abc"), lcase("x")
分隔
select concat-_ws("i","am","man");
字符串查找函数:
find_in_set("abc","123,456,abc");
findld("abc","123","456","abc");
返回子串str1在字符串str2中的位置:
locate ("a","123a456")
position("a" in "123a123")
instr("123a123","a")
获取指定位置的子串:
elt(1,"a","b","c")
left("man",2)
right("man",1)
substring("iamman",2,5)
字符串去空函数:
ltrim(" hello wrold!")
rtrim(" hello ")
trim(" hello world ")
字符串替换函数:
insert("hello wrold",7,5,"jie")
replace("hello admin","admin","jie")
用于处理数值的函数
绝对值函数:abs(x)
向上取整函数:ceil(x)
向下取整函数:floor(x)
取模函数:mod(x,y)
随机数函数:rand(1)
四舍五入函数:round("3.1415926",3)
数值截取函数:truncate("3.1415926",3)
用于处理时间日期的函数
获取当前日期:curdate(),current_date()
获取当前时间:curtime(),current_time()
获取当前日期时间:select now();
从日期中选择出月份数:month(date),monthname(date)
从日期中选择出周数:week('2022-02-02 11:11:11')
从日期中选择出周数:year(date)
从时间中选择出小时数:hour(time)
从时间中选择出分钟数:minute(time)
从时间中选择出今天是周几:weekday(date),dayname(date)