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 Math Functions
 

MySQL Math Functions

Aanchal Sharma
Article byAanchal Sharma
EDUCBA
Reviewed byRavi Rathore

Updated May 25, 2023

MySQL Math Functions

 

 

Introduction to MySQL Math Functions

In MySQL, we can find several built-in command functions that include functions for string, date, numeric, and also another advanced types of MySQL functions. MySQL Math Functions are the MySQL built-in functions that refer to the numeric type functions and commands to operate the mathematical logic. The Math functions in MySQL are the numeric functions used in the SQL query commands mainly for the mathematical calculations and producing the numeric literals as results. These Math Functions perform numeric handling, but if it receives an error event during query implementation, it returns the NULL value as output. With the various MySQL Math Functions, we use arguments to execute different logical operations and display the numeric values in the MySQL server.

Watch our Demo Courses and Videos

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

Various MySQL Math Functions with Examples

Given below are the various math functions along with their respective details for references and describing their utilities and function roles for the mathematical operations:

1. ABS() Function

This Math function is useful to return the universal or fixed value of a numeric expression provided as arguments.

Code:

SELECT ABS(4);

Output:

MySQL Math Functions 1

2. ACOS() Function

It returns the arccosine of a numeric value, but if the value is not provided in the range -1 to 1, then it returns NULL.

Code:

SELECT ACOS(2);

Output:

MySQL Math Functions 2

3. ASIN() Function

It gives the arcsine of a numeric value, but it returns NULL if it is not provided in the range -1 to 1.

Code:

SELECT ASIN(-1);

Output:

MySQL Math Functions 3

4. ATAN() Function

It gives an arctangent of numeric value.

Code:

SELECT ATAN(2);

Output:

MySQL Math Functions 4

5. ATAN2() Function

It gives the arctangent of the given two variables.

Code:

SELECT ATAN2(2,4);

Output:

MySQL Math Functions 5

6. BIT_AND() Function

It outputs the bitwise AND all the bits in a given expression.

Code:

SELECT BookName, BIT_AND(Price) BITS FROM Books GROUP BY BookName;

7. BIT_COUNT Function

It displays the string illustration of the specified binary value.

Code:

SELECT BIT_COUNT(3) AS Three, BIT_COUNT(5) AS FIVE;

Output:

MySQL Math Functions 7

8. BIT_OR() Function

It gives the bitwise OR of every bit provided in the expressions passed.

Code:

ELECT BookName, BIT_OR(Price) BITS FROM Books GROUP BY BookName;

9. CEIL() Function

It results in the minimum integer value that is not small than the provided numeric argument.

Code:

SELECT CEIL(-2.56);

Output:

MySQL Math Functions 8

10. CEILING() Function

It results in a minimum integer value that is not smaller than the provided numeric argument.

Code:

SELECT CEILING(4.37);

Output:

MySQL Math Functions 9

11. CONV() Function

Changing the numeric value from one base to the other is helpful.

Code:

SELECT CONV(4,12,3);

Output:

MySQL Math Functions 10

12. COS() Function

It provides the cosine of specified numeric values which need to be in radians.

Code:

SELECT COS(65);

Output:

MySQL Math Functions 11

13. COT() Function

It provides the cotangent of specified numeric value.

Code:

SELECT COT(180);

Output:

MySQL Math Functions 12

14. DEGREES() Function

It returns the values which are transformed from radians to degrees.

Code:

SELECT DEGREES(PI());

Output:

MySQL Math Functions 13

15. EXP() Function

It provides the base of the natural logarithm(i.e., ‘e’), raised to the power of a given argument.

Code:

SELECT EXP(5);

Output:

MySQL Math Functions 15

16. FLOOR() Function

This function gives the greatest integer value, which is not larger than the numeric values passed to it.

Code:

SELECT FLOOR(9.23);

Output:

MySQL Math Functions 16

17. FORMAT() Function

This function returns a numeric value rounded to a certain digit of decimal places.

Code:

SELECT FORMAT(582345.654324,2);

Output:

MySQL Math Functions 17

18. GREATEST() Function

It helps to determine the largest value among the arguments provided as inputs.

Code:

SELECT GREATEST(6,12,34,56,82,100);

Output:

MySQL Math Functions 18

19. INTERVAL() Function

In this function, if we pass multiple arguments such as Expr1, Expr2, Expr3, etc., then when Expr1 is less than Expr2, the function provides 0 as output. Similarly, the output will be one if Expr1 is less than Expr3.

Code:

SELECT INTERVAL(5,2,5,7,8,10);

Output:

MySQL Math Functions 19

20. LEAST() Function

The LEAST() function gives the lowest valued input expression from two or more arguments passed in the function.

Code:

SELECT LEAST(7,13,54,16,89,57);

Output:

MySQL Math Functions 20

21. LOG() Function

This function provides the natural logarithm of the implemented numeric value.

Code:

SELECT LOG(54);

Output:

MySQL Math Functions 21

22. LOG10() Function

This function provides the base-10 logarithm of the implemented numeric value.

Code:

SELECT LOG10(50);

Output:

MySQL Math Functions 22

23. MOD() Function

The MOD() function denotes the result value as the remainder of one argument value by dividing by the other provided in the query command.

Code:

SELECT MOD(25,2);

Output:

MOD()

24. OCT() Function

This OCT() function in MySQL is useful for returning a string illustration of the given octal value of the implemented numeric expression. But if we specify a NULL value, it returns NULL as output.

Code:

SELECT OCT(21);

Output:

OCT()

25. PI() Function

This is a math function that helps to provide the value of the pi expression.

Code:

SELECT PI();

Output:

PI()

26. POW() Function

This POW() function provides the value of one argument passed raised to the power of another argument with numeric values specified while executing in the server.

Code:

SELECT POW(2,5);

Output:

POW()

27. POWER() Function

Suppose this POWER() is passed with two arguments, Expr1 and Expr2. Then, on implementation, it outputs the value of Expr1, which is raised to the power of the Expr2 argument.

Code:

SELECT POWER(3,4);

Output:

POWER()

28. RADIANS() Function

This Math Function helps produce the result value of implemented expression transformed from degrees to the form of radians.

Code:

SELECT RADIANS(45);

Output:

RADIANS()

29. ROUND() Function

This ROUND() function provides a numeric value rounded to an integer or also can be applied to round any numeric expression to a certain digit of decimal points.

Code:

SELECT ROUND(88.604);

Output:

ROUND()

30. SIN() Function

The SIN() function is a math function in MySQL that returns the output as the sine of a given numeric value expressed in radians form.

Code:

SELECT SIN(45);

Output:

SIN()

31. SQRT() Function

To fetch a non-negative or positive square root for a numeric value, we use this SQRT() math function in MySQL.

Code:

SELECT SQRT(121);

Output:

MySQL Math Functions 31

32. STD() Function

This math function provides the standard deviation value of any specific numeric expression.

Code:

SELECT STD(Price)Std_Deviation FROM Books;

Output:

STD()

33. STDDEV() Function

This is a standard deviation function as of the mathematical term. If a numeric argument is passed to it and executed, it returns the same standard deviation type value.

Code:

SELECT STDDEV(Price) Std_DeviationFROM Books;

Output:

STDDEV()

34. TAN() Function

TAN() function produces the tangent of a given numeric value or expression represented in radians when executed in MySQL.

Code:

SELECT TAN(60);

Output:

TAN()

35. TRUNCATE() Function

Suppose the TRUNCATE Math function takes two arguments, Expr1 and Expr2; then, on implementation, the process will return numeric Expr1 shortened to Expr2 decimal places. But when the argument Expr2 value is 0, there will be no decimal point in the result.

Code:

SELECT TRUNCATE(4.129065,3);

Output:

MySQL Math Functions 35

Conclusion

The Math functions return the non-relative value for the given variable arguments performing the numeric query operations. For these built-in numeric functions, we must consider arguments such as values from integer and float types or decimal values to conduct the query and execute the result of the Math function.

Recommended Articles

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

  1. Natural Join in MySQL
  2. MySQL Index
  3. Examples of MySQL ROW_NUMBER()
  4. MySQL Root Password

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