mysql 格式整理_MySQL数据库基本操作整理

保存数据    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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值