EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MySQL Tutorial MySQL floor
 

MySQL floor

Updated June 3, 2023

MySQL floor

 

 

Introduction to MySQL floor

MySQL floor function is the mathematical function available in MySQL that is used for the numeric type of values. These numeric values can be either integers or floating-point numbers. If the numeric value is formatted inside the string type of value as a parameter, then that value is also allowed for floor function. In short, any value or expression deduced to the numeric value can be used as a parameter to the floor() mathematical function in MySQL. This function helps us retrieve the maximum integer value that is less or equivalent to the passed value. FLOOR() mathematical function is supported in all the versions of MySQL 4.0 and above that, including MySQL 5.0, MySQL 5.1, MySQL 5.5, MySQL 5.6, MySQL 5.7, MySQL 3.23, MySQL 4.0, and MySQL 4.1.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax

Below is the syntax for the mathematical FLOOR() function in MySQL –

FLOOR(expressionOrNumber);

ExpressionOrNumber – ExpressionOrNumber can be any integer, floating-point, or decimal value. If we wrap this numeric value into strings, these string values will also be accepted. Other than the direct specification of numeric value, any expression that will ultimately deduce to a numeric value is also allowed as a FLOOR() function parameter.

Return value – The FLOOR() function returns the greatest integer value that is less than or equal to the parameter value passed to the function. The return value type depends on the data type of the value passed as the parameter to the FLOOR() function. If the parameter is of integer data type, the return value is also of integer type. While in other cases, if the deduced value of the parameter of the direct specification of the parameter is of floating-point type, then the datatype of the return value is of the floating-point data type itself.

Examples

Here are the following examples mentioned below

1. Using FLOOR() function with positive values

We will consider the positive numeric value say 3.59, and then use the FLOOR function to retrieve the highest integer value that is less than or equivalent to the 3.59 value. Let us execute the following SQL query statement and observe the output –

SELECT FLOOR(3.59);

The output of the above query statement execution is as follows –

mysql floor output 1

Let us consider one more example of positive value. But in this example, we will use an expression that will evaluate the value that is of numeric type. Consider the expression 5 * 1.65, whose actual value is 8.25, and use this expression in the FLOOR() function to retrieve the maximum integral value less than the passed value using the following query statement –

SELECT FLOOR(5 * 1.65);

The output of the above query statement execution is as follows –

mysql floor output 2

Now, we will consider a positive number wrapped as a string and use it as a FLOOR() function parameter. For example, consider the “56.569” value that is used in the following manner –

SELECT FLOOR("56.569");

The output of the above query statement execution is as follows –

mysql floor output 3

2. Using FLOOR() function with negative values

We will consider the negative numeric value say -65.55, and then use the FLOOR function to retrieve the highest integer value that is less than or equivalent to the -65.55 value. Let us execute the following SQL query statement and observe the output –

SELECT FLOOR(-65.55);

The output of the above query statement execution is as follows –

mysql floor output 4

Let us consider one more example of a negative value. But in this example, we will use an expression that will evaluate the value that is of numeric type. Consider the expression 8 * -91.65, whose actual value is −733.2, and use this expression in the FLOOR() function to retrieve the maximum integral value less than the passed value using the following query statement –

SELECT FLOOR(8 * -91.65);

The output of the above query statement execution is as follows –

output 5

Now, we will consider a negative number wrapped as a string and use it as a FLOOR() function parameter. For example, consider the “-98.154” value that is used in the following manner –

SELECT FLOOR("-98.154");

The output of the above query statement execution is as follows –

output 6

3. Using the FLOOR() function with values in the table

Let us see how we can use the FLOOR() function in the query statements on the values of the columns. We will create one table named workers using the following query statement –

CREATE TABLE 'workers' (
'developer_id' int(11) NOT NULL AUTO_INCREMENT,
'team_id' int(11) NOT NULL,
'name' varchar(100) DEFAULT NULL,
'position' varchar(100) DEFAULT NULL,
'technology' varchar(100) DEFAULT NULL,
'salary' int(11) DEFAULT NULL,
PRIMARY KEY ('developer_id'),
UNIQUE KEY 'name' ('name')
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1;

Now, we will insert some records in the worker’s table using the following query statements –

INSERT INTO `workers` VALUES
(1,1,'Payal','Developer','Angular',30000),
(2,1,'Heena','Developer','Angular',10000),
(3,3,'Vishnu','Manager','Maven',25000),
(4,3,'Rahul','Support','Digital Marketing',15000),
(5,3,'Siddhesh','Tester','Maven',20000),
(6,7,'Siddharth','Manager','Java',25000),
(7,4,'Brahma','Developer','Digital Marketing',30000),
(8,1,'Arjun','Tester','Angular',19000),
(9,2,'Nitin','Developer','MySQL',20000),
(10,2,'Ramesh','Administrator','MySQL',30000),
(11,2,'Rohan','Admin',NULL,20000),
(12,2,'Raj','Designer',NULL,30000);
Select * from `workers`;

that gives the following output after the execution of the query –

output 7

Now we will calculate the average salary using the following query statement –

SELECT avg(salary) from workers;

The execution of the above query statement gives the following output –

output 8

If we want to retrieve the average salary in integer format with the greatest value that is less than or equivalent to the average value using the FLOOR() function using the following query statement –

SELECT FLOOR (avg(salary)) from workers;

The execution of the above query statement gives the following output

output 9

Conclusion – MySQL floor

MySQL 4.0 and all the above versions of MySQL support the mathematical function FLOOR(). We can retrieve the maximum value in integer format that is less or equivalent to the passed numeric number or expression whose results can be either the floating value of an integer or decimal value.

Recommended Articles

We hope that this EDUCBA information on “MySQL floor” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. MySQL EXISTS
  2. CEIL in MySQL
  3. MySQL Math Functions
  4. MySQL Lock Table

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW