一.字符串函数
curtime()
now()
unix_timestamp(now())
unix_timestamp(date)//unix时间戳
from_unixtime()
//与unix时间戳相互转换
week()
year()
hour()
minute()
……
select concat(name,"age is",age) fromusers;
insert(str,x,y,insert)//将字符串x位置开始y个位置替换成insert
select
lower(str) upper(str)//转化大小写
select * from user where upper(name)='AAA';
left (str ,x) right(str,x)//分别返回左边和右边的x个字符
select left("abcdee",3),right("abcdedd",3),left("abcdedd",null);
lpad(str,n,pad),rpad(str,n,pad)//用字符串pad对str最左边或最右边补到n位
ltrim()
substring(str,x,y)//返回字符串中得第x位置起,取y个字符
二.数值函数
abs(x)
// 返回x的绝对值
ceil(x)
//返回大于x的最小整数
floor(x)//返回小于x的最大整数
mod(x,y) 返回x/y的膜
rand()
//0-1之间随机数
round(x,y)//返回参数x的四舍五入的有y位小数的值
truncate(x,y) //返回数字x截断y位小数的结果
三.日期函数
用php的时间戳来完成
select
curdate()
select
now()
select
unix_timestamp(now())
select
from_unixtiom(1293433835);
select from_unixtime()
select
week(now())
select
minute/hour(curtime())
select
data_format(now(),"%Y-%m-%d%H%i%s")
四.流程控制函数
create
table
salary(idint,salary decimal(9,2));
insert into salary
values(1,1000);
*****
if(value,t
f)
select
if(salary) >3000,
'height','low')from
salary;
ifnull(value1,value2)
select
id,salary,ifnull(salary,0)
from
salary
case when[value1]
then[result1]...else[default]end
case when ...then
select case when salary<=300
then 'low'
else 'high'
end
from salary;
五.其他函数
database()
version()
//查看数据库当前版本
user()
//查看当前用户
inet_aton(ip)
//返回ip地址的网络自解序
inet_ntoa()
//返回网络自解序代表的ip地址
password()
//将字符串加密,给mysql系统用户用的
select
password('123456');
md5()
//给网站用户加密
select * from mysql.user \G;//从mysql库中user表查看