SQLite 3 reference · Math Functions
SQLite SIGN() Function
Return -1, 0 or 1 depending on whether a number is negative, zero or positive. Non-numeric text gives NULL.
SQLite 3
Syntax
sign(X)
Parameters
| Parameter | Description |
|---|---|
X |
A number (text that looks like a number is converted). |
Return value
-1, 0, 1, or NULL.
Examples
SELECT sign(-3) AS neg, sign(0) AS zero, sign(2.5) AS pos;
Output
neg | zero | pos -1 | 0 | 1
SELECT name, stock,
CASE sign(stock) WHEN 0 THEN 'sold out' ELSE 'in stock' END AS status
FROM products
WHERE product_id IN (2, 3);
Output
name | stock | status Clean Code | 15 | in stock The Pragmatic Programmer | 0 | sold out
Related
ABS()· Return the absolute value of a number, so abs(-7) is 7. NULL gives NULL and text that isn't a number gives 0.0.- SQL Aggregate Functions · tutorial