Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Reviewing SQL and numbers
So you think you can count
13. Function mod()
Round and other functions
Review and practice

Instruction

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?

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 maximum number of hp. Name the second column health_points.

Stuck? Here's a hint!

Use mod(hp, 7).