位置:首頁 > 數據庫 > MySQL教學 > MySQL abs()函數

MySQL abs()函數

ABS(X)

ABS()函數返回X的絕對值,請考慮以下的例子:

mysql> SELECT ABS(2);
+---------------------------------------------------------+
| ABS(2)                                                  |
+---------------------------------------------------------+
| 2                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT ABS(-2);
+---------------------------------------------------------+
| ABS(2)                                                  |
+---------------------------------------------------------+
| 2                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)