SIGN
Descriptionβ
Returns the sign of x
. Negative, zero or positive numbers correspond to -1, 0 or 1 respectively.
Syntaxβ
SIGN(x)
Parametersβ
Parameter | Description |
---|---|
<x> | independent variable |
Return valueβ
Returns an integer:
-
If x > 0, it returns 1, representing a positive number.
-
If x = 0, it returns 0, representing zero.
-
If x < 0, it returns -1, representing a negative number.
-
If x is NULL, it returns NULL.
Exampleβ
select sign(3);
+-------------------------+
| sign(cast(3 as DOUBLE)) |
+-------------------------+
| 1 |
+-------------------------+
select sign(0);
+-------------------------+
| sign(cast(0 as DOUBLE)) |
+-------------------------+
| 0 |
+-------------------------+
select sign(-10.0);
+-----------------------------+
| sign(cast(-10.0 as DOUBLE)) |
+-----------------------------+
| -1 |
+-----------------------------+
select sign(null);
+------------+
| sign(NULL) |
+------------+
| NULL |
+------------+