Example 1
Classify each sensor reading as rising, stable, or falling
Sensor A has a positive delta (15), so SIGN returns 1. Sensor B has no change (0), so SIGN returns 0. Sensor C has a negative delta (-8), so SIGN returns -1. The magnitude of the delta is discarded — only the direction is preserved.
CREATE TABLE readings (sensor VARCHAR(10), delta INT);
INSERT INTO
readings
VALUES
('A', 15),
('B', 0),
('C', -8);SELECT
sensor,
delta,
SIGN (delta) AS direction
FROM
readings
ORDER BY
sensor;| sensor | delta | direction |
|---|---|---|
| A | 15 | 1 |
| B | 0 | 0 |
| C | -8 | -1 |
Identical syntax and result across all engines.