Difference between revisions of "% MODULO"
From SQLZOO
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>a % b</th></tr> <tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td><...") |
|||
| (One intermediate revision by one user not shown) | |||
| Line 23: | Line 23: | ||
SELECT MOD(yr,10), | SELECT MOD(yr,10), | ||
yr, city | yr, city | ||
| − | FROM games | + | FROM gisq.games |
</source> | </source> | ||
<source lang='sql' class='def'> | <source lang='sql' class='def'> | ||
| Line 36: | Line 36: | ||
<li>[[MOD |MOD function]]</li> | <li>[[MOD |MOD function]]</li> | ||
</ul> | </ul> | ||
| + | |||
| + | {{Languages}} | ||
Latest revision as of 12:03, 2 September 2012
| a % b | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | No | MOD(a,b) |
| mysql | Yes | MOD(a,b) |
| oracle | No | MOD(a,b) |
| postgres | Yes | MOD(a,b) |
| sqlserver | Yes | |
% (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