MOD

From SQLZoo
Compatibility
MOD(a,b)
EngineOKAlternative
ingresYes
mysqlYesa % b
oracleYes
postgresYesa % b
sqlserverNoa % b

MOD

MOD(a,b) returns the remainder when a is divied by b

If you use MOD(a, 2) you get 0 for even numbers and 1 for odd numbers.

If you use MOD(a, 10) you get the last digit of the number a.

 MOD(27,2) ->  1
 MOD(27,10) ->  7

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

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

See also

Language:Project:Language policy English  • Deutsch
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects
  • Your server today is: Laa-Laa