保存数据 insert into 表名 values(字段值,字段值,...);
指定字段插入 insert into 表名 (字段名) values (字段值);
查询数据 select * from 表名 where 条件;
修改数据 update 表名 set 字段名=字段值,字段名=字段值,... where 条件;
删除数据 delete from 表名 where 条件;
查询到的字段更名 select 原字段名 新字段名 from 表名;
查询去重 select distinct 字段名 from 表名;
in 查询某个字段的值为多个的时候 select * from where 字段名 in(值1,值2,...);
查询某个字段的值不为**的时候 select * from where 字段名 not in(值1,值2,...);
between查询在**之间(之内) select * from where 字段名 between 值1 and 值2;
查询不在**之间的(之外) select * from where 字段名 not between 值1 and 值2;
模糊查询: like
_:代表单个未知字符
%:代表0个或者多个未知字符
升序 select * from 表名 order by 字段 asc;
降序 select * from 表名 order by 字段 desc;
分组 select 字段 from 表名 group by 字段;
分页查询 select * from 表名 limit (页数-1)*每页数量,每页数量 -----limit 7,7
取余 mod(7,2) -----7%2
获取当前日期+时间 select now();
获取当前日期 select curdate();
获取当前时间 select curtime();
从年月日时分秒中提取日期 select date(now());
从年月日时分秒中提取时间 select time(now());
从年与日时分秒中提取时间分量:
年 select extract(year from now()); ------select extract(year from 字段) from 表名;
月 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());
日期格式化:
%Y 四位年 YYYY
%y 两位年 yy
%m 两位月
%c 一位月
%d 日
%H 24小时
%h 12小时
%i 分
%s 秒
-------select date_format(now(),'%Y年%m月%d日 %H时%i分%s秒');
非标准格式转换为标准格式
str_to_date('非标准格式的时间',格式); --------select str_to_date('2018年11月16日 15时49分08秒','%Y年%m月%d日 %H时%i分%s秒');
ifnull(x,y) ----update emp set comm = ifnull(comm,0);