MySql中函数的理解与运用

 显示当前的日期

select current_date();

显示当前的时分秒

select current_time();

在当前的日期上加上十天

select date_add(current_date(),interval 10 day);

在当前的日期上减去十天

select date_sub(current_date(),interval 10 day);

计算两个日期相差多少天

select datediff('2018-9-1','2018-7-29');

创建一个帖子,可显示时间内容等

create table msg (id int primary key auto_increment,content varchar(30) not null,sendtime datetime);

显示帖子上的时间

select content,date(sendtime) from msg;

字符串函数


显示一个字段的字符集

select charset(id) from msg;

显示一个字符串的长度

select length(content),id from msg;

将内容中的s字符全部换成c字符

select replace(content,'s','c'),id from msg;

将content里的第二个到第三个字符截取出来

select substring(content,2,5),id from msg;

数学函数

求绝对值

select abs(-13.14);

向上取整

select ceiling(13.14);//结果为14

向下取整

select floor(13.14);//结果为13

保留两位小数,当第三位小数满五时向前进一位

select format(13.1452,2);//结果为13.15

产生0-1之间的随机数

select rand();

查看当前用户

select user();

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值