SUBSTRACT
All functions > MATH > SUBSTRACT
Subtracts the second number from the first and returns the result.
Syntax
SUBSTRACT(number1: T, number2: T) → T
sql
Type Parameters:
T
: Numeric types: BIGINT, FLOAT, DOUBLE, DECIMAL (both args same type). Temporal: TIMESTAMP-INTERVAL→TIMESTAMP, TIMESTAMP-TIMESTAMP→INTERVAL, DATE-DATE→INTERVAL
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
number1 | T | Yes | Number to subtract from |
number2 | T | Yes | Number to subtract |
Returns
Same as input type - BIGINT, FLOAT, DOUBLE, or DECIMAL. For temporal: TIMESTAMP - INTERVAL → TIMESTAMP, TIMESTAMP - TIMESTAMP → INTERVAL, DATE - DATE → INTERVAL
Notes
- Both arguments must be of the same numeric type
- For temporal types, supports subtracting intervals and calculating differences
- Returns NULL if either operand is NULL
- Order matters:
SUBSTRACT(a, b)
≠SUBSTRACT(b, a)
- Operator form:
number1 - number2