# Difference between revisions of "MOD"

From SQLZOO

(One intermediate revision by one user not shown) | |||

Line 19: | Line 19: | ||

<div class='ht'> | <div class='ht'> | ||

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

<source lang='sql' class='def e-sqlserver'>SELECT yr % 10, yr, city | <source lang='sql' class='def e-sqlserver'>SELECT yr % 10, yr, city | ||

FROM games | FROM games | ||

+ | </source> | ||

+ | <source lang='sql' class='def e-oracle'>SELECT MOD(yr,10), | ||

+ | yr, city | ||

+ | FROM gisq.games | ||

</source> | </source> | ||

<source lang='sql' class='def'>SELECT MOD(yr,10), | <source lang='sql' class='def'>SELECT MOD(yr,10), | ||

Line 32: | Line 36: | ||

<li>[[CEIL |CEIL function]]</li> | <li>[[CEIL |CEIL function]]</li> | ||

</ul> | </ul> | ||

+ | |||

+ | {{Languages}} |

## Latest revision as of 13:09, 2 September 2012

MOD(a,b) | ||
---|---|---|

Engine | OK | Alternative |

ingres | Yes | |

mysql | Yes | a % b |

oracle | Yes | |

postgres | Yes | a % b |

sqlserver | No | a % 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