MySQL提供了实现各种功能的函数
mysql> select abs(-123);
+-----------+
| abs(-123) |
+-----------+
| 123 |
+-----------+
1 row in set (0.00 sec)
mysql> select round(1.6);
+------------+
| round(1.6) |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)
mysql> select round(2.4);
+------------+
| round(2.4) |
+------------+
| 2 |
+------------+
1 row in set (0.01 sec)
mysql> select mod(10,3);
+-----------+
| mod(10,3) |
+-----------+
| 1 |
+-----------+
1 row in set (0.00 sec)
mysql> select power(12,3);
+-------------+
| power(12,3) |
+-------------+
| 1728 |
+-------------+
1 row in set (0.00 sec)
mysql> select round(1.6);
+------------+
| round(1.6) |
+------------+
| 2 |
+------------+
mysql> select round(1.49,1);
+---------------+
| round(1.49,1) |
+---------------+
| 1.5 |
+---------------+
mysql> select sqrt(8);
+--------------------+
| sqrt(8) |
+--------------------+
| 2.8284271247461903 |
+--------------------+
1 row in set (0.00 sec)
mysql> select sqrt(25);
+----------+
| sqrt(25) |
+----------+
| 5 |
+----------+
1 row in set (0.00 sec)
mysql> select truncate(3.12345,3);
+---------------------+
| truncate(3.12345,3) |
+---------------------+
| 3.123 |
+---------------------+
1 row in set (0.00 sec)
mysql> select ceil(1.09); // 向下取整
+------------+
| ceil(1.09) |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)
mysql> select ceil(1.4);
+-----------+
| ceil(1.4) |
+-----------+
| 2 |
+-----------+
mysql> select floor(1.08);
+-------------+
| floor(1.08) |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> select floor(1.99); //向上取整
+-------------+
| floor(1.99) |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> select greatest(10,30),least(10,20);
+-----------------+--------------+
| greatest(10,30) | least(10,20) |
+-----------------+--------------+
| 30 | 10 |
+-----------------+--------------+
1 row in set (0.01 sec)
mysql> select greatest(10,30),least(10,20);
+-----------------+--------------+
| greatest(10,30) | least(10,20) |
+-----------------+--------------+
| 30 | 10 |
+-----------------+--------------+
1 row in set (0.01 sec)
对表中数据记录进行集中概括而设计的一类函数
mysql> select id,avg(score) as '平均值' from info;
+----+-----------+
| id | 平均值 |
+----+-----------+
| 1 | 77.222222 |
+----+-----------+
1 row in set (0.00 sec)
mysql>
mysql> select id,count(score) as '个数' from info;
+----+--------+
| id | 个数 |
+----+--------+
| 1 | 9 |
+----+--------+
1 row in set (0.00 sec)
mysql> select name,min(score) as '最小值' from info;
+--------+-----------+
| name | 最小值 |
+--------+-----------+
| 张三 | 56.00 |
+--------+-----------+
1 row in set (0.01 sec)
mysql> select name,max(score) as '最大值' from info;
+--------+-----------+
| name | 最大值 |
+--------+-----------+
| 张三 | 98.00 |
+--------+-----------+
1 row in set (0.00 sec)
mysql> select name,sum(score) as '总计' from info;
+--------+--------+
| name | 总计 |
+--------+--------+
| 张三 | 695.00 |
+--------+--------+
1 row in set (0.00 sec)
mysql> select length('abjcoi');
+------------------+
| length('abjcoi') |
+------------------+
| 6 |
+------------------+
1 row in set (0.00 sec)
mysql> select length('a bjc o i');
+---------------------+
| length('a bjc o i') |
+---------------------+
| 9 |
+---------------------+
1 row in set (0.01 sec)
mysql>
mysql> select trim(' djs kw ');
+-------------------+
| trim(' djs kw ') |
+-------------------+
| djs kw |
+-------------------+
1 row in set (0.01 sec)
mysql> select trim(' d js k w ');
+---------------------+
| trim(' d js k w ') |
+---------------------+
| d js k w |
+---------------------+
1 row in set (0.00 sec)
mysql> select concat('x','hfiwo');
+---------------------+
| concat('x','hfiwo') |
+---------------------+
| xhfiwo |
+---------------------+
1 row in set (0.00 sec)
mysql>
mysql> select upper('anf');
+--------------+
| upper('anf') |
+--------------+
| ANF |
+--------------+
1 row in set (0.00 sec)
mysql>
mysql> select lower('AHIBD');
+----------------+
| lower('AHIBD') |
+----------------+
| ahibd |
+----------------+
1 row in set (0.00 sec)
mysql>
mysql> select left('feiowv',3);
+------------------+
| left('feiowv',3) |
+------------------+
| fei |
+------------------+
1 row in set (0.00 sec)
mysql>
mysql> select right('feiowv',2);
+-------------------+
| right('feiowv',2) |
+-------------------+
| wv |
+-------------------+
1 row in set (0.00 sec)
mysql>
mysql> select repeat('adc',2);
+-----------------+
| repeat('adc',2) |
+-----------------+
| adcadc |
+-----------------+
1 row in set (0.00 sec)
mysql>
mysql> select concat('a',space(5),'b');
+--------------------------+
| concat('a',space(5),'b') |
+--------------------------+
| a b |
+--------------------------+
1 row in set (0.00 sec)
mysql>
mysql> select replace('tress','ss','aa');
+----------------------------+
| replace('tress','ss','aa') |
+----------------------------+
| treaa |
+----------------------------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> select strcmp(67,98);
+---------------+
| strcmp(67,98) |
+---------------+
| -1 |
+---------------+
1 row in set (0.00 sec)
mysql> select strcmp(2,1);
+-------------+
| strcmp(2,1) |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> select strcmp(23,29);
+---------------+
| strcmp(23,29) |
+---------------+
| -1 |
+---------------+
1 row in set (0.00 sec)
mysql> select strcmp(3,3);
+-------------+
| strcmp(3,3) |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
mysql> select substring('mysqldiwnwknfs',3,4);
+---------------------------------+
| substring('mysqldiwnwknfs',3,4) |
+---------------------------------+
| sqld |
+---------------------------------+
1 row in set (0.00 sec)
mysql>
mysql> select reverse('adciwo');
+-------------------+
| reverse('adciwo') |
+-------------------+
| owicda |
+-------------------+
1 row in set (0.00 sec)
mysql>
常用的日期时间函数
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2020-08-25 |
+------------+
1 row in set (0.00 sec)
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 15:57:44 |
+-----------+
1 row in set (0.02 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2020-08-25 15:58:34 |
+---------------------+
1 row in set (0.01 sec)
mysql>
mysql> select month('2020-8-23');
+--------------------+
| month('2020-8-23') |
+--------------------+
| 8 |
+--------------------+
1 row in set (0.00 sec)
mysql>
mysql> select week('2020-8-24');
+-------------------+
| week('2020-8-24') |
+-------------------+
| 34 |
+-------------------+
1 row in set (0.00 sec)
mysql>
mysql> select hour(curtime());
+-----------------+
| hour(curtime()) |
+-----------------+
| 16 |
+-----------------+
1 row in set (0.00 sec)
mysql>
mysql> select hour('15:57:53');
+------------------+
| hour('15:57:53') |
+------------------+
| 15 |
+------------------+
1 row in set (0.00 sec)
mysql> select minute(curtime());
+-------------------+
| minute(curtime()) |
+-------------------+
| 4 |
+-------------------+
1 row in set (0.00 sec)
mysql> select minute(curtime());
+-------------------+
| minute(curtime()) |
+-------------------+
| 4 |
+-------------------+
1 row in set (0.00 sec)
mysql> select second(curtime());
+-------------------+
| second(curtime()) |
+-------------------+
| 32 |
+-------------------+
1 row in set (0.00 sec)
mysql> select dayofweek(curdate());
+----------------------+
| dayofweek(curdate()) |
+----------------------+
| 3 |
+----------------------+
1 row in set (0.00 sec)
mysql>
mysql> select dayofmonth(curdate());
+-----------------------+
| dayofmonth(curdate()) |
+-----------------------+
| 25 |
+-----------------------+
1 row in set (0.00 sec)
mysql>
mysql> select dayofyear(curdate());
+----------------------+
| dayofyear(curdate()) |
+----------------------+
| 238 |
+----------------------+
1 row in set (0.00 sec)
mysql>