abs() 是 MySQL 的数学函数。该函数用于获取给定数字的绝对值。
语法
select abs(num);
参数:
num:取绝对值的数值。
返回
此函数返回数字的绝对值。
示例 1
Select abs(11);
输出:
mysql> Select abs(11);
+---------+
| abs(11) |
+---------+
| 11 |
+---------+
1 row in set (0.00 sec)
示例 2
Select abs(11.2);
输出:
mysql> Select abs(11.2);
+-----------+
| abs(11.2) |
+-----------+
| 11.2 |
+-----------+
1 row in set (0.00 sec)
示例 3
Select abs(-11.2);
输出:
mysql> Select abs(-11.2);
+------------+
| abs(-11.2) |
+------------+
| 11.2 |
+------------+
1 row in set (0.00 sec)
示例 4
Select abs(-11*2);
输出:
mysql> Select abs(-11*2);
+------------+
| abs(-11*2) |
+------------+
| 22 |
+------------+
1 row in set (0.00 sec)
示例 5
Select abs(11*-2);
输出:
mysql> Select abs(11*-2);
+------------+
| abs(11*-2) |
+------------+
| 22 |
+------------+
1 row in set (0.00 sec)