ABS

ABS is a function in SQL that returns the absolute value of a specified number. The absolute value of a number is its value regardless of its sign.

ABS(X)

  • x: The numeric expression or field from which the absolute value will be calculated.

Example

SELECT ABS(-243);

Output

243

Explanation

In the above example, the built-in MySQL ABS() function is used to return the absolute value of a number. The ABS() function takes a single argument, in this case -243, and returns its absolute value, which is 243.

ABS(number)

  • number: This parameter represents the numeric value for which the absolute value needs to be calculated. Its input can be any numeric data type supported by PostgreSQL, such as integer, decimal, or float. The function returns the non-negative value of this parameter.

Example

SELECT ABS(-5);

Output

5

Explanation

The ABS function in PostgreSQL returns the absolute value of a number. In this example, it converts -5 into 5.

ABS( numeric_expression )

  • numeric_expression: The argument for which the absolute value is to be returned. It can be an expression of the numeric data type category, excluding the bit data type.

Example

SELECT ABS(-10);

Output

10

Explanation

In SQL Server, the ABS function returns the absolute value of a number. In the given example, ABS(-10) returns 10, because the absolute value of -10 is 10.

ABS(number)

  • number: This parameter refers to a numeric value from which the absolute value is to be calculated. It can be a constant, variable, or column of a table, and can contain either integer or decimal values.

Example

SELECT ABS(-123) FROM dual;

Output

123

Explanation

The ABS function is used to return the absolute value of a number, meaning the returned value is always positive. The argument can be a number of any kind, and in this case, it turns the negative number -123 into a positive number, 123.

ABS(X)

  • x: This is a numeric value for which the absolute result is calculated. The input can be a negative, zero, or a positive number. ABS(X) will return the absolute value of X.

Example

SELECT ABS(-10);

Output

10

Explanation

The ABS function in SQL returns the absolute value of the specified number. In this example, the absolute value of -10 is 10.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.