MySQL MOD function is one of the Mathematical Function which is used to find the Modulus. Or say, it will find the remainder.
In this article, we will show you, How to find Modulus of different values in MySQL using Command Prompt, and Workbench with examples.
MySQL MOD Syntax
The syntax of the MOD in MySQL is as shown below:
SELECT MOD(X, Y);
SELECT X % Y;
SELECT X MOD Y;
This function will divide the X with Y value and retunes the reminder.
MySQL MOD Function Example 1
The MOD Function is used to return the remainder or Modulus of given value. The following query will show multiple ways to use MOD function.
SELECT MOD(25, 5);
SELECT MOD(25, 4), MOD(29, 9);
SELECT 29 MOD 9, 28 MOD 5, 29 % 5;
MySQL MOD Example 2
The MySQL MOD Function also allows you to find Modulus of a column data.
In this example, we are going to find the Modulus of Yearly Income column divided by 9.
MOD(YearlyIncome, 9) AS Mod9Income,
Sales MOD 5 AS Mod5Sales
FROM `MySQL Tutorial`.customer;
Thank You for Visiting Our Blog