欢迎来到Python专栏
♀️作者介绍:前PLA队员 目前是一名普通本科大三的软件工程专业学生
IP坐标:湖北武汉
目前技术栈:C/C++、Linux系统编程、计算机网络、数据结构、Mysql、Python(目前在学)
博客介绍:通过分享学习过程,加深知识点的掌握,也希望通过平台能认识更多同僚,如果觉得文章有帮助,请您动动发财手点点赞,本人水平有限,有不足之处欢迎大家扶正~
最后送大家一句话共勉:知不足而奋进,望远山而前行。愿大家都能早日进大厂实现财富自由~
————————————————
select current_date();
+----------------+
| current_date() |
+----------------+
| 2017-11-19 |
+----------------+
select current_time();
+----------------+
| current_time() |
+----------------+
| 13:51:21 |
+----------------+
select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2017-11-19 13:51:48 |
+---------------------+
select date_add('2017-10-28', interval 10 day);
+-----------------------------------------+
| date_add('2017-10-28', interval 10 day) |
+-----------------------------------------+
| 2017-11-07 |
+-----------------------------------------+
select date_sub('2017-10-1', interval 2 day);
+---------------------------------------+
| date_sub('2017-10-1', interval 2 day) |
+---------------------------------------+
| 2017-09-29 |
+---------------------------------------+
select datediff('2017-10-10', '2016-9-1');
+------------------------------------+
| datediff('2017-10-10', '2016-9-1') |
+------------------------------------+
| 404 |
+------------------------------------+
create table tmp(
id int primary key auto_increment,
birthday date
);
insert into tmp(birthday) values(current_date());
mysql> select * from tmp;
+----+------------+
| id | birthday |
+----+------------+
| 1 | 2017-11-19 |
+----+------------+
mysql> create table msg (
id int primary key auto_increment,
content varchar(30) not null,
sendtime datetime
);
比
mysql> create table msg (
id int primary key auto_increment,
content varchar(30) not null,
sendtime datetime
);
mysql> insert into msg(content,sendtime) values('hello1', now());
mysql> insert into msg(content,sendtime) values('hello2', now());
mysql> select * from msg;
+----+---------+---------------------+
| id | content | sendtime |
+----+---------+---------------------+
| 1 | hello1 | 2017-11-19 14:12:20 |
| 2 | hello2 | 2017-11-19 14:13:21 |
+----+---------+---------------------+
select content,date(sendtime) from msg;
select * from msg where date_add(sendtime, interval 2 minute) > now();
理解:
------------------------------|-----------|-------------|------------------
初始时间 now() 初始时间+2min
select charset(ename) from EMP;
select concat(name, '的语文是',chinese,'分,数学是',math,'分') as '分数' from
student;
select length(name), name from student;
注意:length函数返回字符串长度,以字节为单位。如果是多字节字符则计算多个字节数;
如果是单字节字符则算作一个字节。比如:字母,数字算作一个字节,中文表示多个字节数
(与字符集编码有关
select replace(ename, 'S', '上海') ,ename from EMP;
select substring(ename, 2, 2), ename from EMP;
select concat(lcase(substring(ename, 1, 1)),substring(ename,2)) from EMP;
绝对值
select abs(-100.2);
向上取整
select ceiling(23.04);
向下取整
select floor(23.7);
保留2位小数位数(小数四舍五入)
select format(12.3456, 2);
产生随机数
select rand();
user() 查询当前用户
md5(str)对一个字符串进行md5摘要,摘要后得到一个32位字符串
database()显示当前正在使用的数据库
password()函数,MySQL数据库使用该函数对用户加密