SQLite mod() Function

The SQLite mod() function returns the remainder after dividing the specified two numbers.

Syntax

Here is the syntax of the SQLite mod() function:

mod(y, x)

Parameters

y

Required. dividend.

x

Required. divisor.

Return value

The SQLite mod() function returns the remainder of y divided by x, which is the remainder of y/x.

The SQLite mod() function will return NULL if the parameter is NULL.

The SQLite mod() function will return NULL if you provide a non numeric value.

Examples

This example shows the basic usage of the SQLite mod() function:

SELECT
    mod(3, 2),
    mod(3.3, 1.2);
    mod(3, 2) = 1.0
mod(3.3, 1.2) = 0.9

here,

  • 3 / 2 = 1 ... 1, so mod(3, 2) returned 1.0.
  • 3.3 / 1.2 = 2 ... 0.9, so mod(3.3, 1.2) returned 0.9.