Skip to main content

SIGN

Functions › Number

Returns -1 for a negative number, 0 for zero and 1 for a positive number.

Syntax​

SIGN( <number> )

Arguments​

ArgumentDescription
<number>A number, or text that reads as a number.

Returns​

An integer for an integer argument; otherwise a float (-1.0, 0.0 or 1.0). NULL when <number> is NULL. Text that does not read as a number fails the query.

Usage notes​

  • Runs after the rows are read; it is not pushed to the data store.

Examples​

Count stock movements in and out:

SELECT SIGN(m.quantity) AS direction, COUNT(*) AS movements
FROM data.stock_movements m
GROUP BY SIGN(m.quantity)
directionmovements
-1212
03
1187

See also​

ABS · CASE