SQL ABS() Function Example | ABS() in SQL
SQL ABS() is an inbuilt function that is used for returning the absolute value of a number when passed as an argument, i.e., the negative number gets converted to an absolute positive number.
SQL ABS() method is used to get the absolute value of the number passed as an argument. An expression is the numeric value or numeric data type. The bit data type is not allowed. All of the above platforms support the SQL syntax of ABS().
SELECT ABS (expression);
Expression: The number whose absolute positive value is to be retrieved.
SELECT ABS (-25);
SELECT ABS (-25.6);
SELECT ABS (24.65 * -1);
SELECT ABS (2 + 55 – 77);
Here, the ABS() function also works on multiple values.
Let’s apply the ABS() function to a table.
Consider Table: (Agents)
Suppose, if we want to get a unique absolute value from the columns named COMMISSION after multiplying it by (-1), then the following query has to be executed.
SELECT DISTINCT (ABS (commission* (-1))) "DISTINCT (ABS ())" FROM Agents;
|DISTINCT (ABS ())|
Here, we had used the DISTINCT clause, which is used for displaying unique values and ABS() function, which converted negative value to positive ones.