mysql(5)函数一
1)---返回字符的字节数
SELECT LENGTH('ABC是');
PS:JBK中中文是2个字节,utf8中中文3个字节。
---返回字符个数
select char_length(‘’)
select * from student where char_length(sname)=2;
select * from student where sname like '__';
---随机函数rend(),返回0到1 之间的随机小数
select rend();
--随机查询出两条语句
select * from student order by rend() limit 2;(效率很低)
select round [rend()];--1或0
select round [rend()*3]+1;--1到4 之间的随机整数
2)日期
date_add (now()interval 10 day)--10天后
date_add (now()interval -10 day)--10天前
date_add (now ()interval -10 week)--10周前
date_add (now()interval 10minute)--返回10分钟前
--查看10天内的注册人数
select count(*) from nember where regiate between '2014-1-19' and ‘2014-1-29’;
select count(*) from nember where regiate beyween date_add (now(),interval -10 day) and now();
select date_add(now(),interval -10 day),now();
select datediff(curdate(),'1991-11-8');求出两日期相差的天数;
格式化日期函数date_formate(ps:Y是四位年份,y是2位年份)
select date_format(now()'%Y年%m月%d日%H%m%s');
select timestampdiff(hour,'2013-1-2','2015-3-2’)--返回两对象间的小时差;
select weekday (now());
---日期时间在存储时可使用int unisigned
from unixtime() 讲数字表达日期格式化成标准yyyy-mm--dd hh:ii:ss
select form unixtime(13776555100);--