SQLite 3 reference · Math Functions
SQLite ABS() Function
Return the absolute value of a number, so abs(-7) is 7. NULL gives NULL and text that isn't a number gives 0.0.
SQLite 3
Syntax
abs(X)
Parameters
| Parameter | Description |
|---|---|
X |
A number (text that looks like a number is converted). |
Return value
A number of the same type, or NULL.
Examples
SELECT abs(-7) AS a, abs(3.5) AS b, abs(NULL) AS c;
Output
a | b | c 7 | 3.5 | NULL
SELECT name, salary, abs(salary - 120000) AS distance_from_120k
FROM employees
ORDER BY distance_from_120k
LIMIT 3;
Output
name | salary | distance_from_120k Priya Nair | 115000 | 5000 Lucas Martin | 112000 | 8000 Jonas Berg | 140000 | 20000
In other languages
ABS()· PostgreSQL
Related
ROUND()· Round a number to a given number of decimal places (0 by default). Halves round away from zero.SIGN()· Return -1, 0 or 1 depending on whether a number is negative, zero or positive. Non-numeric text gives NULL.- SQL Aggregate Functions · tutorial