码迷,mamicode.com
首页 > 数据库 > 详细

mysql数值运算符和函数

时间:2017-03-28 19:38:12      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:整数   0.00   mysql   运算符   函数   style   images   src   image   

技术分享

 

mysql> SELECT CEIL(3.01);  # 进1取整
+------------+
| CEIL(3.01) |
+------------+
| 4 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT FLOOR(3.99);  # 舍1取整
+-------------+
| FLOOR(3.99) |
+-------------+
| 3 |
+-------------+
1 row in set (0.00 sec)

mysql> SELECT 3 / 4; #真正的除法

+--------+
| 3 / 4 |
+--------+
| 0.7500 |
+--------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT 3 DIV 4;  #整数除法
+---------+
| 3 DIV 4 |
+---------+
| 0 |
+---------+
1 row in set (0.00 sec)

mysql> SELECT 5 % 3;  #取余数
+-------+
| 5 % 3 |
+-------+
| 2 |
+-------+
1 row in set (0.00 sec)

mysql> SELECT 5 MOD 3;    #取余数
+---------+
| 5 MOD 3 |
+---------+
| 2 |
+---------+
1 row in set (0.01 sec)

mysql> SELECT POWER(3,3);  #幂运算
+------------+
| POWER(3,3) |
+------------+
| 27 |
+------------+
1 row in set (0.05 sec)

mysql> SELECT ROUND(3.654, 2);  #四舍五入
+-----------------+
| ROUND(3.654, 2) |
+-----------------+
| 3.65 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT ROUND(3.654, 1);
+-----------------+
| ROUND(3.654, 1) |
+-----------------+
| 3.7 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(125.89, 2);  # 数字截取
+---------------------+
| TRUNCATE(125.89, 2) |
+---------------------+
| 125.89 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(125.89, 1);
+---------------------+
| TRUNCATE(125.89, 1) |
+---------------------+
| 125.8 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(125.89, 0);
+---------------------+
| TRUNCATE(125.89, 0) |
+---------------------+
| 125 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(125.89, -1);  #很少用到
+----------------------+
| TRUNCATE(125.89, -1) |
+----------------------+
| 120 |
+----------------------+

mysql数值运算符和函数

标签:整数   0.00   mysql   运算符   函数   style   images   src   image   

原文地址:http://www.cnblogs.com/toudoubao/p/6635995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!