先展示一下我随手写的表,下面列出的函数将以此表进行一 一举例子
展示整个表的语句如下
select *from stu; //stu是自定义的表名
数学函数
ROUND四舍五入
select round(1.23);
ROUND指定保留位数的四舍五入
select round(1.2345,3);
CEIL向上取整
select ceil(1.23);
FLOOR向下取整
select floor(9.99);
TRUNCATE截断
select truncate(1.4499,2);
MOD取模
select mod(-10,-3);
ORDER–BY DESC倒序排序
select * from student order by age desc;
ORDER–BY ASC正序排列
select *from stu order by age asc;
聚合函数
AVG返回平均值
select avg(age) from stu;
COUNT返回指定列中非NULL值的数量
select count(age) from stu;
COUNT返回表的行数(包含有NULL值的列)
select count(*) from stu;
MAX返回最大值
select max(age) from stu;
MIN返回最小值
select min(age) from stu;
SUM求和
select sum(age) from stu;
流程控制语句(if、case)
IF 语句
select if(10>5,'大于','不大于');
CASE-----WHEN
类似switch—case
select age,(
case age //age为表的某一列
when 56 then '年过半百'
when 29 then '没到三十'
else '海星'
END
)as isyoung
from stu; //stu为表名
时间相关函数
NOW返回当前系统的年月日+时间
select now();
CURTIME返回当系统的时间
select curtime();
字符、字符串相关函数
UPPER小写字母转为大写字母
select upper('asd');
LOWER大写字母转小写字母
select lower('ASD');
ASCII返回字符ASCII码
select acsii('A');
SUBSTRING截取字符串
select substring('buala',1,3);
LEFT / RIGHT从左侧/右侧截取字符串
select left('桃花岛主',3);
select right('桃花岛主',2);