Open In App

FLOOR(), GREATEST() and LEAST() Function in MariaDB

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

1. FLOOR() Function :
The MariaDB, The FLOOR function is used for returns the largest integer value that is equal to or less than a number. In this function, a number will be passed as a parameter and it will return the floor value of the number. This function working is similar to the CEIL() Function.

Syntax :

FLOOR( number )

Example-1 :

SELECT FLOOR(-17.7);

Output :

18

Example-2 :

SELECT FLOOR(34.2);

Output :

34

Example-3 :

SELECT FLOOR(73);

Output :

73

2. GREATEST() Function :
In MariaDB, The GREATEST Function is used for the greatest value in a list of expressions. In this function, many expression will be passed as a parameter and it will return the greatest value in the list. It works similar to the max() function in python. If the list of expressions is numeric values then this function will return the greatest numeric value. If the list of expressions is string values, then the function will return the largest string value. if null will passed in the parameter then it will return NULL.

Syntax :

GREATEST( expr1, expr2, ... expr_n )

Example-1 :

SELECT GREATEST(45, 19, 109);

Output :

109

Example-2 :

SELECT GREATEST('gfg','xyz,'abc');

Output :

abc

Example-3 :

SELECT GREATEST('geeks', 'for',NULL,'geek');

Output :

NULL

3. LEAST() Function :
In MariaDB, The LEAST() function will return the smallest value in a list of expressions. In this function, a list of expressions will be passed and it will return the least value in them.It works similar to the min() function in python. If the list of expressions is numeric values then this function will return the least numeric value.If the list of expressions is string values, then the function will return the least string value. if NULL will be passed in the parameter then it will return NULL.

Syntax :

LEAST( expr1, expr2, ... expr_n )

Example-1 :

SELECT LEAST(87, 49, 12);

Output :

12

Example-2 :

SELECT LEAST('GFG', 'ABC', 'XYZ');

Output :

ABC

Example-3 :

SELECT LEAST('GEEKS',NULL,'FOR');

Output :

NULL

Last Updated : 12 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads