Max(), Min() and Mod() Function in MariaDB
Last Updated :
08 Nov, 2022
1. Max() Function : In MariaDB, the Max() function is used to returns the maximum value of an expression. In this function, a query is passed and in the eligible records which value will be maximum, that will return a result. It works like maximum function in the processed query. An expression will be passed as a parameter and it will return the maximum value in the expression. Syntax :
Max(expression)
Parameter : Required. An expression. expression : The input value. Returns : The maximum value in the expression. Table – IPL
Team_id |
Teamname |
Score |
1 |
RR |
140 |
2 |
CSK |
210 |
3 |
MI |
160 |
4 |
DC |
170 |
Example-1 :
SELECT Max(Score) AS MAX_Score
FROM IPL;
Output :
Example-2 :
SELECT Max(Score) AS MAX_Score
FROM IPL
WHERE Score < 190;
Output :
Example-3 :
SELECT Max(Score) AS MAX_Score
FROM IPL
WHERE Score < 160;
Output :
2. Min() Function : In MariaDB, the Min() function is used to returns the minimum value of an expression. In this function, a query is passed and in the eligible records which value will be minimum, that will return a result. It works like minimum function in the processed query. An expression will be passed as a parameter and it will return the minimum value in the expression. Syntax :
Min(expression)
Parameter : Required. An expression. expression : The input value. Returns : The minimum value in the expression. Example-1 :
SELECT Min(Score) AS Min_Score
FROM IPL;
Output :
Example-2 :
SELECT Min(Score) AS Min_Score
FROM IPL
WHERE Score > 150;
Output :
Example-3 :
SELECT Min(Score) AS Min_Score
FROM IPL
WHERE Score > 170;
Output :
3. Mod() Function : In MariaDB, the Mod() function used to return the remainder of n divided by m.In this function, two-parameter will be passed first is n (a value that will be divided by m) and the second will be m (a value that will be divided into n). The function uses the formula of n / m and returned what will be a remainder without any rounding. Syntax :
MOD(n, m)
OR
n MOD m
OR
n % m
Parameters : Required. Two numeral values.
- n : Dividend (Value that will be divided).
- m : Divisor (Value which the dividend is being divided by).
Returns : Remainder value (without any rounding) as the result of the division. Example-1 :
SELECT MOD(20, 5);
Output :
0
Example-2 :
SELECT 21 MOD 4;
Output :
1
Example-3 :
SELECT 51 % 7;
Output :
2
Share your thoughts in the comments
Please Login to comment...