Difference between revisions of "MOD"

From SQLZOO
Jump to: navigation, search
Line 30: Line 30:
 
<ul>
 
<ul>
 
   <li>[[FLOOR |FLOOR function]]</li>
 
   <li>[[FLOOR |FLOOR function]]</li>
   <li>[[CEIL function]]</li>
+
   <li>[[CEIL |CEIL function]]</li>
 
</ul>
 
</ul>

Revision as of 10:08, 16 July 2012

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

With a GROUP BY region statement each region shows up just once. The SUM column gives the total for each region.

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

See also

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense