div() 是 MySQL 的数学函数。该函数用于整数除法。
语法
select n div m;
参数
n : 除数
m : 被除数
返回
此函数将结果作为整数值返回。
示例 1
Select 4 div 2;
输出:
mysql> Select 4 div 2;
+---------+
| 4 div 2 |
+---------+
| 2 |
+---------+
1 row in set (0.00 sec)
+---------+
| 4 div 2 |
+---------+
| 2 |
+---------+
1 row in set (0.00 sec)
示例 2
Select 56.2 div 3;
输出:
mysql> Select 56.2 div 3;
+------------+
| 56.2 div 3 |
+------------+
| 18 |
+------------+
1 row in set (0.00 sec)
+------------+
| 56.2 div 3 |
+------------+
| 18 |
+------------+
1 row in set (0.00 sec)
示例 3
Select 4.9 div -4;
输出:
mysql> Select 4.9 div -4;
+------------+
| 4.9 div -4 |
+------------+
| -1 |
+------------+
1 row in set (0.01 sec)
+------------+
| 4.9 div -4 |
+------------+
| -1 |
+------------+
1 row in set (0.01 sec)