ABS()
Published May 29, 2023
Contribute to Docs
The ABS()
function in SQL returns the absolute value of a given number. That means, it effectively converts negative numbers to positive numbers, and leaves positive numbers unchanged.
Syntax
SELECT ABS(number)FROM table_name;
Example
In this example, the following data is given in the transactions
table:
temperature_id | temperature |
---|---|
1 | -5.7 |
2 | -18.5 |
3 | 30.2 |
The ABS()
function is used to calculate the absolute temperature value:
SELECT temperature_id, ABS(temperature) AS absolute_tempFROM transactions;
The output will be:
temperature_id | absolute_temp |
---|---|
1 | 5.7 |
2 | 18.5 |
3 | 30.2 |
Note:
ABS()
is compatible with various SQL database systems such as MySQL, PostgreSQL, Oracle, and SQL Server.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.