insert       -- 增
delete       -- 删
truncate     -- 删
update       -- 改
select       -- 查
-- 更删改查实例
(
select * from constraint_test;
insert constraint_test value (null,'田七','男',3);    				 -- 增值列可以写列明或者null
insert constraint_test value (null,'小明','男',1),             -- 添加多行数据,用逗号分隔
                             (null,'小红','女',3);
insert constraint_test(ename,esex) value('王八','男');				 -- 添加指定的列,注意非空的列必须指定,自增长列不需指定

delete from constraint_test;                          				 -- 删除指定表中的所有记录
truncate table constraint_test;                       				 -- 删除指定表中的所有记录第二种方式
delete from constraint_test where ename='李四';       				 -- 删除指定表中满足条件的记录
                     
update constraint_test set esex='女';                  			   -- 更新指定表中的所有数据
update constraint_test set esex='男' where             				 -- 更新指定表中满足条件的数据,注意:update不能只用in
did = (select did from department where dname='研发部')
or did = (select did from department where dname='销售部');

select * from constraint_test;                                 -- 查询指定表中的所有列
select ename,esex from constraint_test c where not exists      -- 查询指定表中满足条件的指定列,查询没有部门的员工名字
(select * from department d where c.did = d.did);
select * from constraint_test limit 0,2;                       -- 查询指定表中指定行的信息,<limit 第一行从0开始,要查询几行>
)

*********************************************************************************************************************************************************
-- 下列实例用Employee数据库
(

-- 创建数据库
create database Employee;
show databases;
use Employee;

-- 创建表(共4张表)
-- 表一:部门表(部门编号,部门名称,部门电话)
create table dept(
	did int primary key auto_increment,	                -- 部门编号
	dname varchar(20),		               	              -- 部门名称
	dtel  varchar(20),		              	              -- 部门电话
	eid int					                                    -- 部门经理
)auto_increment=1;

-- 表二:员工表(员工编号,员工姓名,员工性别,入职时间,员工工资,部门编号)
create table emp(
	eid int primary key auto_increment,	                -- 员工编号
	ename varchar(20),				                        	-- 员工姓名
	esex  char(2),		                                  -- 员工性别
	estartime datetime,					                        -- 入职时间
	epay float,						                              -- 员工工资
	did int,						                                -- 部门编号
  foreign key (did) references dept(did)  
)auto_increment=1;

-- 表三:员工账号表(账号编号,员工账号,账号密码,账号状态,员工编号)
create table accounts(
	aid int primary key auto_increment,	              	-- 账号编号
	account varchar(20),				                        -- 员工账号
	apwd varchar(20),				                            -- 账号密码
	astate varchar(1),				                          -- 账号状态
	eid int,                                            -- 员工编号
  foreign key (eid) references emp(eid)
)auto_increment=1;

-- 表四:员工历史档案表(档案编号,开始时间,结束时间,就业地,职务,员工编号)
create table history(
	hid int primary key auto_increment,		              -- 档案编号
	hstarttime datetime,				                        -- 开始时间
	hendtime datetime,				                          -- 结束时间
	hcity varchar(20),				                          -- 就业地
	hwork varchar(20),				                          -- 职务
	eid int,                                            -- 员工编号
  foreign key (eid) references emp(eid)
)auto_increment=1;

desc dept;
desc emp;
desc accounts;
desc history;

insert into dept values(did,'董事会','111111',1);
insert into dept values(did,'财务部','222222',3);
insert into dept values(did,'市场部','333333',5);
insert into dept values(did,'研发部','444444',9);
insert into dept values(did,'行政部','555555',12);
insert into dept values(did,'质检部','666666',66);

insert into emp values(eid,'tom','男','2005-09-13',9000.00,1);
insert into emp values(eid,'jack','男','2005-10-22',8500.00,1);
insert into emp values(eid,'kelly','女','2006-02-19',5000.00,2);
insert into emp values(eid,'red','女','2007-10-31',4800.00,2);
insert into emp values(eid,'blue','男','2006-05-10',6000.00,3);
insert into emp values(eid,'green','女','2006-06-19',5500.00,3);
insert into emp values(eid,'peter','女','2006-08-21',5800.00,3);
insert into emp values(eid,'cat','女','2008-11-09',6300.00,3);
insert into emp values(eid,'dog','男','2009-09-02',7800.00,4);
insert into emp values(eid,'lion','男','2010-12-09',7200.00,4);
insert into emp values(eid,'suny','男','2011-04-06',7500.00,4);
insert into emp values(eid,'tiger','男','2009-12-27',6400.00,5);
insert into emp values(eid,'bell','男','2010-11-25',6200.00,5);
insert into emp values(eid,'bull','女','2013-12-15',5500.00,3);
insert into emp values(eid,'eecc','女','2011-1-18',5800.00,4);

insert into accounts values(aid,'tom','111','1',1);
insert into accounts values(aid,'jack','222','1',2);
insert into accounts values(aid,'kelly','333','1',3);
insert into accounts values(aid,'red','444','1',4);
insert into accounts values(aid,'blue','555','1',5);
insert into accounts values(aid,'green','666','0',6);
insert into accounts values(aid,'peter','777','1',7);
insert into accounts values(aid,'cat','888','0',8);
insert into accounts values(aid,'dog','999','1',9);
insert into accounts values(aid,'lion','000','0',10);
insert into accounts values(aid,'suny','123','1',11);
insert into accounts values(aid,'tiger','234','0',12);
insert into accounts values(aid,'bell','345','1',13);

insert into history values(null,'2000-10-01','2001-02-02','襄阳','行政总监',1);
insert into history values(null,'2001-02-08','2002-06-06','深圳','总经理',1);
insert into history values(null,'2003-02-11','2004-02-25','青岛','会计',3);
insert into history values(null,'2004-03-01','2006-02-01','威海','会计师',3);
insert into history values(null,'2005-09-23','2006-09-24','达州','出纳',4);
insert into history values(null,'2006-10-08','2007-10-31','成都','出纳',4);
insert into history values(null,'2002-10-22','2004-04-18','宜昌','市场专员',5);
insert into history values(null,'2004-05-08','2006-04-30','北京','区域经理',5);
insert into history values(null,'2005-11-01','2006-10-28','武汉','市场专员',6);
insert into history values(null,'2006-11-01','2006-06-19','青岛','市场专员',6);
insert into history values(null,'2004-04-12','2005-04-21','徐州','市场专员',7);
insert into history values(null,'2005-05-08','2006-08-20','武汉','市场专员',7);
insert into history values(null,'2004-10-09','2006-10-10','南京','市场专员',8);
insert into history values(null,'2006-10-21','2008-10-31','北京','市场专员',8);
insert into history values(null,'2006-05-08','2007-05-08','太原','程序员',9);
insert into history values(null,'2007-06-01','2009-09-01','衡阳','架构师',9);
insert into history values(null,'2008-11-28','2009-11-30','北京','程序员',10);
insert into history values(null,'2009-12-01','2010-12-08','南京','程序员',10);
insert into history values(null,'2008-02-01','2010-02-02','青岛','程序员',11);
insert into history values(null,'2010-03-01','2011-04-03','武汉','数据库管理员',11);
insert into history values(null,'2004-09-11','2007-09-10','深圳','行政助理',12);
insert into history values(null,'2007-09-29','2009-12-25','北京','行政专员',12);
insert into history values(null,'2008-11-20','2009-11-22','广州','行政助理',13);
insert into history values(null,'2009-12-01','2010-11-20','北京','行政助理',13);

select * from dept;
select * from emp;
select * from accounts;
select * from history;
) 


-- 比较运算符 >  <  >=  <=  = (!= <>)两个都表达不等于
(
/*查询工资大于6000的员工信息*/
select * from emp;
select * from emp where epay>6000;
select * from emp where not epay<=6000;   -- 如果工资<=6000放回true进行非(not)运算等于false,如果工资>6000放回false进行非(not)运算等于true。
/*查询不叫tiger的员工信息*/
select * from emp where ename!='tiger';
select * from emp where ename!='tiger';
select * from emp where not ename='tiger';
)
-- 逻辑运算符 and :并且  or :或者  not :非,取反
(
/*查询男性员工工资大于7000的员工信息*/
select * from emp where esex='男' and epay>7000;
select * from emp where not esex='女' and not epay<=7000;
/*查询员工在襄阳和深圳的工作经历信息*/
select * from history where hcity='襄阳' or hcity='深圳';
select * from history where not hcity<>'襄阳' or not hcity<>'深圳';
/*查询没在北京工作过的工作经历信息*/
select * from history where hcity!='北京';
select * from history where not hcity='北京';
)
-- 模糊查询:like
-- 通配符:
--   _ :一个字符位    
--   % :匹配多个字符  
--  []:匹配范围内的一个字符   
--  [^]:匹配不在范围内的一个字符
(
/*查询t开头的员工信息*/
select * from emp where ename like 't%';
/*查询名字中有a字母的员工信息*/
select * from emp where ename like '%a%';
)
-- 指定列的别名,使用as关键字或空格:
(
select ename as '姓名',esex as '年龄' from emp;   -- 用as关键字取别名
select ename '姓名',esex '年龄' from emp;         -- 用空格取别名
)
--  在mysql中进行字符串的拼接要使用concat函数,concat函数支持一个或者多个参数.
(
/*需求:把员工的姓名和性别合并成一个字段显示,然后取别名为'员工信息'*/
select concat(ename,'==',esex) as '员工信息' from emp;
)
/*
order by 
desc : 降序
asc : 升序
*/
(
/*案例1:查询员工信息并对工资升序排序*/
select * from emp order by epay;                -- 默认为升序排序
/*案例2:查询员工信息并对部门编号升序,工资降序*/
select * from emp order by did asc, epay desc;  -- 先对部门进行升序排序,部门相同再按工资降序排序。
)

-- distinct : 查询不重复的记录
(
/*需求:查询所有员工在哪些城市工作过,要求数据不重复。*/
select distinct hcity from history;
)
-- null和空字符串的用法 : 
-- null:表示没有值   is null  is not null 
-- 空字符串:有值的  =''  !=''  <>''
(
/*需求:性别不是空的员工信息*/
select * from emp where esex<>'' and esex is not null;  -- '' 和 null 不一样
)
--  between ...and ... 查询满足某个条件范围的记录  逻辑and
(
/*需求:查询入职时间在'2010-01-01'-'2016-01-01'之间的员工信息(两种方式完成)*/
select * from emp where estartime>='2010-01-01' and estartime<='2016-01-01';
select * from emp where estartime between'2010-01-01' and '2016-01-01';
)
-- in : 包含哪些值,和逻辑or类似
(
/*--需求:查询工作经历表中,在'北京'或者'青岛'工作过的信息。(2种方式完成)*/
select * from history where hcity='北京' or hcity='青岛';
select * from history where hcity in ('北京','青岛');
)
/*
聚合函数: 对数据进行总结,统计计算。
特点:将多行数据汇总成一行显示 

语法:count(): 计数
      max(): 最大值
      min():最小值
      avg(): 平均数

1. count(1)和count(*)的作用:
都是检索表中所有记录行的数目,不论其是否包含null值。
count(1)比count(*)效率更高
count(字段)的作用是检索表中的这个字段的非空行数,不统计这个字段值为null的记录
注意,聚合函数不能用于where字句中。
*/
(
/*查询公司有多少员工*/
select count(*) from emp;
/*需求:查询公司有多少女员工。*/
select count(*) from emp where esex='女';
/*需求:查询'市场部' 的员工总数,最高工资,最低工资,平均工资。*/ 
select count(*) '员工总数',max(epay) '最高工资',min(epay) '最低工资',avg(epay) '平均工资' from emp where did = 
(select did from dept where dname='市场部');                   -- 这里用了子查询,子查询的结果作为外查询的条件
)
-- 15、查询部分记录
/*
limit 起始行,查询几行
起始行从0开始
*/
(
/*需求:查询emp表2-5行的记录*/
select * from emp limit 1,4;         -- 由于起始行从0开始,1就表示表中的第2行数据。
)
-- 16、分组查询
/*
group by : 分组汇总,根据“By”指定的规则对数据进行分组
注意:group by 子句中,必须要指定需要分组的列,而且必须是出现在
select 之后除了聚合函数之外所有的列。

having : 把分组之后的数据进行筛选和过滤,类似于where的作用
注意:聚合函数必须要写在having后面,绝对不能写在where后面!!

where: 在分组之前,把不符合条件的数据过滤掉,where条件中绝对不能写聚合函数!!!

条件查询的顺序:
where ------>  group by  -----> having 
*/
(
/*案例1:计算男,女员工各有多少人*/
select esex,count(*) from emp group by esex;
/*案例2:查询每个部门各有多少人*/
select did,count(*) from emp group by did;
select d.dname '部门名称',count(*) '人数' from emp e,dept d where e.did=d.did group by d.dname; -- 完整的写法,用到了等值连接
/*案例3:查询显示部门人数大于3的部门*/
select did,count(*) from emp group by did having count(*)>3;
select d.dname '部门名称',count(*) '人数' from emp e,dept d where e.did=d.did group by d.dname having count(*)>3; -- 完整的写法 , where->group by->having 

/*需求:查询每个部门的平均工资,并且平均工资大于6000*/
select did,avg(epay) from emp group by did having avg(epay)>6000;
select d.dname '部门名称',avg(epay) '平均工资' from emp e,dept d where e.did=d.did group by d.dname having avg(epay)>6000; -- 完整的写法 , where->group by->having 
)
-- 17、使用with rollup实现统计功能
(
/*案例1:查询每个部门各有多少人并统计公司总人数*/
select did,count(*) from emp group by did with rollup;
)
/*子查询和连接查询*/

-- 18.子查询
/*什么是子查询?
	  1、当一个查询语句嵌套在另外一个查询语句中称之为子查询。
    2、子查询的结果作为外查询的条件

	  在使用子查询时,当子查询的返回值只有
		一个时用=,当子查询的返回值有多个时用in
    子查询能使用的操作符:
       in  
       not in 
       =  !=
		   >  <  <>
*/
(
	/*案列1、查询所有研发部的员工信息*/
  -- 步骤:
  -- 1、查询研发部的did
  select did from dept where dname='研发部';   -- 4
  -- 2、根据步骤1查询研发部的员工信息
  select * from emp where did = 4;
  -- 合并,用子查询
  select * from emp where did = 
   (select did from dept where dname='研发部');
  select * from emp where did in                         -- 返回一条数据也可以用in
   (select did from dept where dname='研发部');
  
		
	/*2、查询研发部和市场部的员工信息。*/
	select * from emp where did in                         -- 返回多条数据用in
    (select did from dept where dname in ('研发部','市场部'));

  /*3、查询不在财务部的员工信息*/
  select * from emp where did !=
   (select did from dept where dname='财务部');
  select * from emp where did not in                     -- not运算取反,(不等于财务部) 
   (select did from dept where dname='财务部');
)		
-- 19.嵌套子查询?
/*
		子查询包含一个子查询,
    嵌套子查询包含多个子查询。
*/
(
	/*案例:*/
	/*1、查询和kelly在同一个城市工作过的员工信息。*/
	-- 步骤: 
  -- 1、查询kelly工作过的城市
  select hcity from history where eid = 
     (select eid from emp where ename='kelly');
  -- 2、查询在这些城市工作过的员工的eid
  select eid from history where hcity in 
    (select hcity from history where eid = 
     (select eid from emp where ename='kelly'));
  -- 3、查询员工信息
  select * from emp where eid in 
	 (select eid from history where hcity in(
     select hcity from history where eid =( 
      select eid from emp where ename='kelly')))
			 and ename <> 'kelly';
)
-- 20.子查询和delete,update,子查询可以它们的条件表达式提供结果集
(
	/*案例:*/
		/*1、删除tom所有的工作经历*/
      delete from history where eid=
       (select eid from emp where ename='tom');
		
		/*2、将所有研发部的员工工资加500元*/
       update emp set epay=epay+500 where did =
         (select did from dept where dname='研发部');        
)
-- 21.exists 关键字 :用于检查一个子查询是否至少会返回一行数据(即检测行的存在),返回值为true或false。
(
/*案例 1. 查询没有工作经历的员工信息。*/
select * from emp e where not exists (select * from history h where e.eid=h.eid);
select * from emp where eid not in (select eid from history);
)

/*链接查询主要有:等值连接、内连接、左外连接、右外连接、完全连接*/
-- 22.等值连接
(
/*
		总结:等值查询技巧
		通常把要查询的列放在select 后面,列中间用逗号分开,把涉及到的
		表放在from后面用逗号分开并把每个表都取别名,接着把几个表的主外键
		关系放在where后面,然后用=号连接,还可以加上其他条件。
    最后如果还可以根据需要加上分组语句。
*/
/*1、如查询所有的员工姓名,账号及其所在部门*/
select e.ename,account,dname from emp e, accounts a,dept d 
where e.eid = a.eid and e.did=d.did;
/*2、查询所有性别为男的员工的姓名和工作经历*/
select e.ename,h.* from emp e,history h where e.eid=h.eid and e.esex='男';
/*3、查询每个部门的部门名称及平均工资*/
select * from dept;
select d.dname '部门名称',avg(e.epay) '平均工资' from dept d,emp e where d.did=e.did group by d.dname;
/*查询工资比其所在部门平均工资高的员工信息*/
select e1.* from emp e1,(select d.dname '部门名称',avg(e.epay) 'avg' ,e.did from dept d,emp e where d.did=e.did group by d.dname) e2 
where e1.did=e2.did and e1.epay>e2.avg;   # 这里建立了一个虚拟表e2,然后将他们等值连接关联起来,e1表的工资大于其所在部门的平均工资,因为部门已经得到了关联。
)
-- 23.内连接:关键字inner join...on,只有左,右2个表相匹配的行才能在结果中显示,作用和等值连接一样。
(
/*查询所有员工及其所在部门名称*/
select e.ename,d.dname from emp e inner join dept d on e.did=d.did;
/*查询被禁用的账号及其员工信息*/
select e.ename,a.account from emp e inner join accounts a on e.eid=a.eid where a.astate=0;
)
-- 24.左外连接:关键字left join,左边的表的行全部显示,左边连接右边的值,右边的表如果没有匹配的值,显示为null
(
/*案例:查询所有员工及其工作经历,没有工作经历的员工也查询出来。*/
select * from emp e left join history h on e.eid=h.eid; 
)
-- 25.右外连接:关键字right join, 右边的表的行全部显示,右边连接左边的,左边的表如果没有匹配的值,显示为null
(
/*案例:查询所有员工及其部门,部门没有员工也查询出来。*/
select * from emp e right join dept d on e.did=d.did;
)
-- 26.完全连接:关键字union, 用于合并两个或多个select语句的结果集。 左,右2个表的行都全部显示,如果没有匹配的值,显示为null    
-- 合并的select语句的列数量、类型、顺序必须完全一样
(
/*检索当前所有员工的信息和工作经历。*/
	select * from emp e left join history h on e.eid=h.eid
	union
	select * from emp e right join history h on e.eid=h.eid;

)
-- 27.    一、日期函数
/*MySQL 获得当前日期时间函数*/
select now();
/*当前日期 : 年月日*/
select curdate();
/*当前时间:时分秒*/
select curtime();
-- 28、date_add() , date_sub()  
/*
  语法格式:select date_add(指定时间,interval 年月日间隔数 年月日季选择);
  返回指定日期加上一个时间间隔后的日期
  
  语法格式:select date_sub(指定时间,interval 年月日间隔数 年月日季选择);
  函数从日期减去指定的时间间隔。
*/
(
-- 案例:
/*1、下个月的今天:*/
select date_add(curdate(),interval 1 month);
/*2、上个季度的今天:*/
select date_sub(curdate(),interval 1 quarter);
/*3、去年的今天:*/
select date_sub(curdate(),interval 1 year);
/*4、明年的今天:*/
select date_add(curdate(),interval 1 year);
/*5、2015年1月1日的365天之后,是哪一天*/
select date_add('2015-1-1',interval 365 day);
)
-- 29.datediff() 
/*
语法格式:datediff(结束时间,起始时间)
返回起始时间和结束时间之间的天数。
*/
(
-- 案例:
/*2015-1-2到2015-2-2有多少天*/
select datediff('2015-2-2','2015-1-2');
/*今天距2008-8-8号有多少天*/
select datediff(curdate(),'2008-8-8');
)
-- 30、date() : 
 /*
 语法:date(日期时间表达式)
 提取日期或时间日期表达式中的日期部分。 
*/
(
-- 案例:
/*提取'2003-12-31 01:02:03'的日期部分*/
select date('2003-12-31 01:02:03');
)
-- 31、dayofweek(date)
     /*返回date是星期几(1=星期天,2=星期一,……7=星期六) */
(
 -- 案例:
 select concat('今天是星期:',dayofweek(now())-1);  
)
-- 32.dayofmonth(date) 
    /*返回date是一月中的第几天(在1到31范围内)*/
(
-- 案例:
select dayofmonth(now());
)     
-- 33.dayofyear(date) 
    /*返回date是一年中的第几天(在1到366范围内)*/
(
-- 案例:
 select dayofyear(now());
)
-- 34.month(date) 
    /*返回date中的月份数值*/ 
-- 35.day(date)
     /*返回date中的天数数值*/ 
-- 36.year(date)
     /*返回date的年份(范围在1000到9999)*/ 
-- 37.quarter(date) 
    /*返回date是一年的第几个季度 */
(
-- 案例:
     select month(now());
     select day(now());
     select year(now());
     select quarter(now());
)
-- 38.week(date,first)
    /*返回date是一年的第几周(first默认值0,first取值1表示周一是周的开始,0从周日开始)*/
(
-- 案例
select week(curdate(),1);
)
-- 39.DATE_FORMAT(date,format) 
   /*根据format字符串格式化date值*/
(
-- 案例
select date_format(now(),'%y#%m#%d#%h&%m&%s');
)
-- 40.extract() 
   /*函数用于返回日期/时间的各个部分,比如年、季、月、日、小时、分钟等等。*/
(
-- 案例
select extract(year from now());
select extract(quarter from now());
select extract(month from now());
select extract(day from now());
select extract(hour from now());
select extract(minute from now());
select extract(second from now());
)
-- 41.timestampdiff() : 计算两个日期的时间差函数
/*select timestampdiff(年月日季选择,起始时间,结束时间);*/
(
select timestampdiff(day,'2017-4-9','2017-8-9');  -- select datediff('2017-8-9','2017-4-9'); 等同
select timestampdiff(year,'2017-5-9','2019-9-10'); 
)
-- 42.last_day() 函数:返回月份中的最后一天
(
-- 案例
select last_day('2017-5-3');
)
(
-- 案例:
	/*今天是几号*/ 
  select extract(day from now());   				
	/* 今天是星期几*/	
  select dayofweek(now())-1;	
	/* 今天是第几季度*/
  select quarter(curdate());    			
  /* 本月一共有多少天?*/
  select last_day(curdate()); 
	/* 本月的第一天是星期几?*/
  select dayofweek(date_sub(curdate(),interval day(curdate())-1 day))-1;
	/* 本周的周一是几号?*/
  select date_sub(curdate(), interval dayofweek(curdate()-1)-1 day);  
)
--  字符函数
-- 43.concat() 
/*   concat(str1,str2,…)  concat函数可以连接一个或者多个字符串
     concat_ws(x,s1,s2,...) 同concat(s1,s2,...)函数,但是每个字符串直接要加上x 
*/
(
-- 案例
select concat('我','叫','张','三');
select concat_ws('*','我','叫','张','三');
)

-- 44.left(str, length)
/*
     从左开始截取字符串  
     说明:left(被截取字段,截取长度)
*/
(
-- 案例
select left('abcdefghijk',4);
)    
-- 45.从右开始截取字符串 
/*  
   right(str, length) 
   说明:right(被截取字段,截取长度)
*/
(
-- 案例
select right('abcdefghijk',4);
)
-- 46.截取字符串 
/*
     substring(str, pos) 
     substring(str, pos, length) 
     说明:substring(被截取字段,从第几位开始截取) 
     substring(被截取字段,从第几位开始截取,截取长度)
*/
(
-- 案例
select substring('abcdefghijk',4);
select substring('abcdefghijk',4,4);

)

-- 47.char_length(s)  
/*
返回字符串s的字符数
*/
(
-- 案例
select char_length('abcdefghijk');
)
-- 48.insert(s1,x,len,s2) 
/*
将字符串s2替换s1的x位置开始长度为len的字符串
*/
(
-- 案例
select insert ('abcdefg',3,2,'nx'); -- 替换掉s1字符x位置开始的len个字符
)

-- 49.upper(s) 
/*
upper(s): 将字符串s的所有字母变成大写字母
*/
(
-- 案例
select upper('abcdefg');
)
-- 50.lower(s) 
/*
lower(s): 将字符串s的所有字母变成小写字母
*/
(
-- 案例
select lower('ABCDEFG');
)
-- 51.trim(s) : 
/*
去掉字符串s开始和结尾处的空格
*/
(
-- 案例
select trim(' abc defg '); -- 中间的空格不能去掉
)
-- 52.reverse(s) : 
/*
将字符串s的顺序反过来
*/
(
-- 案例
select reverse('abcdefg');
)
-- 数学函数
-- 53.abs(x) : 返回x的绝对值
(
select abs(5);
)
-- 54.ceil(x),ceiling(x) : 返回大于或等于x的最小整数
(
select ceil(1.2369875858);
)
-- 55.floor(x): 返回小于或等于x的最大整数
(
select floor(1.268558552585);
)
-- 56.rand() : 返回0->1的随机数
(
select rand();
)
-- 57.pi() : 返回圆周率(3.141593)
(
select pi();
)
-- 58.round(x,y) : 保留x小数点后y位的值,但截断时要进行四舍五入
(
select round(1.23456,3);
)
-- 59.truncate(x,y) : 返回数值x保留到小数点后y位的值(与round最大的区别是不会进行四舍五入)
(
select truncate(1.23456,3);
)
-- 60.pow(x,y).power(x,y)  : 返回x的y次方
(
select pow(5,3);
)
-- 61.sqrt(x) : 返回x的平方根
(
select sqrt(5);
)
-- 62.mod(x,y) : 返回x除以y以后的余数
(
select mod (5,2);
)