日期函数
currnet_date()---获得当前年月日
select current_date()
currnet_time()---获得当前时间,时分秒
select current_time()
currnet_timetamp()---获得当前时间戳
select current_timestamp()年月日,时分秒
date_add------和date_sub
date_add(date(当前你给的日期,或时间都行),interval +时间)
比如查询当前时间加十分钟后的时间
注意函数可以嵌套使用
select date_add(current_time(),interval 10 minute)
datediff------计算两个日期相差多少天
注意: 这里给的为负数就说明是用第一个日期减第二个date(datetime)------截取当前时间的年月日
create table msg (
id int primary key auto_increment,
content varchar(30) not null,
sendtime datetime
); 创建一张留言表
插入数据: insert into msg(content,sendtime) values('hello1', now())
insert into msg(content,sendtime) values('hello2', now());
now()是获取当前的时间也就是包括年月日时分秒
select date(sendtime) from msg
字符串函数
有了前面日期函数的详解,这里的字符串函数我就讲我认为用得到的,其他我没讲的可以自己下去试试应该是没问题的concat------连接字符串函数
就是能把你给的字符串全部连在一起
当然在一张表里也能将对应的字段连接起来
select concat(name, '的语文是',chinese,'分,数学是',math,'分') as '分数' from
student; 可以自己建一个学生成绩表来实践一下,不要害怕动手手~instr(string,substring)------查找substring(字符或字符串)是否存在于string中
也就是说它是返回字符或字符串的首元素位置
replace(string,search_str,replace_str)------将stirng(字符串)中search_str(某个字符或字符串)替换指定的replace_str(字符或字符串)
比如员工表,表的创建详细在我写的基本查询里最后给了大家可以复制后去尝试

我现在把所有名字中带S的名字将S改为涛

数学函数
我个人认为能用到的如下面abs------绝对值函数
format------保留几位小数
mod------取模运算
就跟编程语言的取模运算一样其他函数
user()------返回当前用户
md5()------对一个字符串进行md5摘要,摘要后得到一个32位字符串
相当于进行了加密
















