一、统计函数
1.count返回行的总数
select count(*) | count(列名) from 表名 where...
2.sum函数返回满足where条件的行的和
select sum(列名) from 表名 where...
3.avg函数返回满足where条件的一列平均值
select avg(列名) from 表名 where...

二、分组统计
1.使用group by子句对列进行分组
select column1,column2,column3.. from table group by column
2.使用having子句对分组后的结果进行过滤
select column1,column2,column3.. from table group by column having...

三、常用的字符串函数
1.charset(str):返回字串字符集
2.concat(str1,str2):连接字符串,有一个null,就返回null
3.insert(str,substring):返回substring在str中出现的位置,没有返回0
4.ucase(str):转大写
5.lcase(str):转小写
6.left(str,length):从str左边开始取length个字符
7.replace(str,search_str,replace_str):在str中用replace_str替换search_str
8.strcmp(str1,str2):逐字符比较两字符串大小
9.substring(str,position,length):从str的position开始取length个长度
10.ltrim(str) rtrim(str)去除前端或后端空格

四、数学相关函数
1.abs(num):绝对值
2.ceiling(num):向上取整
3.floor(num):向下取整
4.format(num,小数位数):保留小数位数
5.least(num1,num2...):求最小值
6.mod():取余
五、日期相关函数
1.current_date():当前日期
2.current_time():当前时间
3.current_timestamp():当前时间戳
4.date(datetime):返回datetime的日期部分
5.date_add(date,interval d_value d_type):在date上加上日期或时间
6.5.date_sub(date,interval d_value d_type):在date上减去一个时间
7.datediff(date1,date2):两个日期差(结果是天)
8.timediff(date1,date2):两个时间差(多少时分秒)
9.now():当前时间
10.year()、month()、date()年月日

六、加密和系统函数
1.user():查询用户
2.md5(str):为str算出一个MD5 32的字符串,加密
3.password(str):原文密码加密
七、流程控制函数
1.if(expr1,expr2,expr3):如果expr1为true,则返回expr2,否则返回expr3
2.ifnull(expr1,expr2):如果expr1不为空,返回expr1,否则返回expr2
3.select case when expr1 then expr2 when expr3 then expr4 else expr5 end:如果expr1为真,返回expr2,如果expr3为真,返回expr4,否则返回expr5