%,MOD

Description

The %,MOD operator is used for modulo operation. Returns the remainder of N divided by M. For more information.

Syntax

  1. > SELECT N % M, N MOD M;

Examples

  1. > select 12 mod 5;
  2. +--------+
  3. | 12 % 5 |
  4. +--------+
  5. | 2 |
  6. +--------+
  7. 1 row in set (0.00 sec)
  1. > create table t2(c1 int, c2 int);
  2. > insert into t2 values (-3, 2);
  3. > insert into t2 values (1, 2);
  4. > select c1 mod 2 from t2;
  5. +--------+
  6. | c1 % 2 |
  7. +--------+
  8. | -1 |
  9. | 1 |
  10. +--------+
  11. 2 rows in set (0.01 sec)
  12. > select c1 mod c2 from t2;
  13. +---------+
  14. | c1 % c2 |
  15. +---------+
  16. | -1 |
  17. | 1 |
  18. +---------+
  19. 2 rows in set (0.01 sec)