So you think you can count
13. Function mod
Round and other functions
Revision and practice


Okay. There is one more useful function related to division. This function is mod(x,y), which returns the remainder of x divided by y.

For instance, mod(9,7) will return 2, because 9/7 is 1 with 2 as the remainder.

In SQL Server the operator to compute the remainder is %: 9%7 returns 2. This % operator is supported by PostgreSQL and MySQL, but not by Oracle.

Shall we do an exercise?


In our game, you can increase your strength by 1 if you sacrifice 7 hp.

For each character, show its name and calculate how many health points will be left if the player decides to sacrifice the maximal number of hp.

Stuck? Here's a hint!

Use mod(hp,7).


Code editor