% MODULO

From SQLZoo
Compatibility
a % b
EngineOKAlternative
ingresNoMOD(a,b)
mysqlYesMOD(a,b)
oracleNoMOD(a,b)
postgresYesMOD(a,b)
sqlserverYes

% (Modulo)

a % b returns the remainder when a is divied by b

If you use a % 2 you get 0 for even numbers and 1 for odd numbers.

If you use a % 10 you get the last digit of the number a.

 27 % 2  ->  1
 27 % 10 ->  7

In this example you get the final digit year of the games.

SELECT MOD(yr,10),
       yr, city
  FROM gisq.games
SELECT yr % 10,
       yr, city
  FROM games

See also

Language:Project:Language policy English  • Deutsch