SQLite 3 reference · Math Functions
SQLite MOD() Function
Return the remainder of dividing one number by another. Unlike the % operator it also works with decimals.
SQLite 3 Since 3.35.0
Syntax
mod(X, Y)
Parameters
| Parameter | Description |
|---|---|
X |
A number (text that looks like a number is converted). |
Y |
The divisor. |
Return value
The remainder, or NULL when Y is 0.
Examples
SELECT mod(10, 3) AS a, mod(7.5, 2) AS b, 7.5 % 2 AS percent_op;
Output
a | b | percent_op 1 | 1.5 | 1
Run this on your computer — see “Get Started” for setup.
SELECT order_id, mod(order_id, 2) = 0 AS even
FROM orders
LIMIT 4;
Output
order_id | even 1 | 0 2 | 1 3 | 0 4 | 1
Run this on your computer — see “Get Started” for setup.
This is one of SQLite's built-in math functions, available since 3.35.0 when SQLite is compiled with
SQLITE_ENABLE_MATH_FUNCTIONS (the default for the sqlite3 command-line tool and most language bindings). The
in-browser SQLite on this site is built without them, so the examples show output from standard SQLite instead.
Version history
| Version | Change |
|---|---|
| SQLite 3.35.0 | Added |
In other languages
MOD()· PostgreSQL
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.TRUNC()· Drop the fractional part of a number, rounding toward zero: trunc(2.7) is 2 and trunc(-2.7) is -2.- SQL Aggregate Functions · tutorial