MySQL Tutorial

MySQL Tutorial MySQL Features MySQL Database Introduction MySQL Environmental Setup MySQL Data Types MySQL variable MySQL Advance table Query MySQL database queries MySQL Entity-Relationship Model MySQL Table Query MySQL Operators MySQL logical conditions MySQL Queries MySQL Clauses Clustered vs Non-Clustered Index MySQL Full text index MySQL Descending Index MySQL Invisible Index MySQL Composite Index MySQL Prefix index MySQL Index MySQL Create index MySQL Drop Index MySQL Show index MySQL Unique index MySQL Table MySQL Variable MySQL View MySQL Constraints MySQL Command Line Client Basic Queries MySQL Stored Procedure MySQL IF Statement MySQL Subquery MySQL Triggers

MySQL Join

MySQL Join MySQL CROSS JOIN MySQL DELETE JOIN MySQL EQUI JOIN MySQL INNER JOIN MySQL Union MySQL NATURAL JOIN MySQL RIGHT JOIN MySQL SELF JOIN MySQL UPDATE JOIN

MySQL Function

MySQL Function MySQL AVG() Function MySQL SUM() Function MySQL String() Function MySQL Advance() Function MySQL Aggregate() Function MySQL COALESCE() Function MySQL Control Flow Function MySQL COUNT() Function MySQL Date And Time Function MySQL GREATEST() Function MySQL ISNULL() Function MySQL LEAST() Function MySQL Math() Function MySQL MAX() Function MySQL MIN() Function MySQL find_in_set() function MySQL ASIN() Function MySQL CEIL() function MySQL CEILING() function MySQL TAN() Function MySQL Truncate() Function MySQL FLOOR() function MySQL LN() function MySQL LOG2() function MySQL LOG10() function MySQL MOD() function MySQL PI() function MySQL POW() function MySQL RADIANS() function MySQL RAND() function MySQL ROUND() function MySQL Character Length Function MySQL Current Date Function MySQL Date Add Function MySQL Date Format Function MySQL Datediff Function MySQL Day Function MySQL Elt Function MySQL Export Set Function MySQL Field Function MySQL Format Function MySQL From Base64 Function MySQL Hex Function MySQL Insert Function MySQL Instr Function MySQL Length Function MySQL CONCAT() function MySQL FIND_IN_SET() function MySQL LIKE() function MySQL LOAD_FILE() function MySQL LOCATE() function MySQL LOG() function MySQL MONTHNAME() function MySQL NOW() function MySQL PERIOD_ADD() function MySQL PERIOD_DIFF() function MySQL POWER() function MySQL QUARTER() function MySQL REVERSE() function MySQL RIGHT() Function MySQL RPAD() function MySQL RTRIM() function MySQL SEC_TO_TIME() function MySQL SOUNDEX() function

Questions

Which Clause is Similar to Having Clause in MySQL

Misc

MySQL Error 1046 - No Database Selected Failed to Start MySQL Service Unit MySQL Service Unit not Found Import MySQL Connector Mudule not Found Error No Module Named MySQL Joins Available in MySQL MySQL Docs MySQL Download For Windows 7 64 Bit MySQL Error Code 1064 MySQL Export MySQL History MySQL Host MySQL Import MySQL Drop All Tables MySQL Drop MySQL Error Code 1175 MySQL Events MySQL Except MYSQL Foreign Key Constraint MySQL If Exists MySQL IndexOf MySQL List All Tables json_extract in MySQL TIMESTAMPDIFF in MySQL MySQL Syntax Checker Sudo MySQL Secure Installation

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic values using a data table. The math function mostly includes ABS(), MOD(), ROUND(), and TRUNCATE() functions.

Syntax

MySQL math function syntax gives below.

SELECT math_function();

MySQL math function requires values or argument.

SELECT math_function(value);

The math functions with multiple values are given in the syntax.

SELECT math_function(value1, value2);

MySQL Math Functions

A list of the math functions with descriptions shows below:

FunctionDescription
ABS()The ABS() function displays the absolute value of a given data number. This function does not display available positive or negative signs with a number. You get only the numerical value of the mathematical operation.
CEIL()The CEIL() function returns the smallest integer value. This integer value is greater than or equal to the given value (n).
FLOOR()The FLOOR() function shows the largest integer value. This integer value is not greater than the given value.
MOD()The mod() function displays the remainder of a division operation. The moderator works on division operation and returns reminder values.
ROUND()The ROUND() function shows the round number of the decimal number or given number.
TRUNCATE()The TRUNCATE() function truncates a decimal point of the given number. This function uses in arithmetic operations.
ACOS (n)The ACOS(N) function shows the "arc cosine" of the given value (n). This function returns a null value when the given value is not in a range of -1 to 1.
ASIN (n)The ASIN(n) function displays the "arc sine" of the given value (n). This function shows a null value when the given value is not in a range of -1 to 1.
ATAN ()This function returns the arctangent of the given value (n). It displays a null value when the given value is not in a range of -1 to 1. This function uses in trigonometric operations.
ATAN2 (n,m), ATAN(m,n)This function displays the arctangent of the two variables or values such as an "n" and "m". This function uses in arithmetic and trigonometric operations.
CONV(n, from_base, to_base)This function converts from a given number base to the required number base. This function uses in arithmetic operations.
COS (n)The COS(n) function returns the cosine of the given value (n). Here, the given value (n) is the radian. This function works on the angle of the trigonometry operation.
COT (n)The COT(n) function shows the cotangent of the given value (n). This function works on the angle of the trigonometry operation. This function uses in trigonometric operations.
CRC32 ()The CRC32() function displays a 32-bit unsigned value. This function determines the cyclic redundancy check of the 32-bit value. This function uses in trigonometric operations.
DEGREES (n)The DEGREES() function converts radian's value into degrees of the given value (n).
 EXP (n)The EXP() function displays the specific power of e raised into the given value (n) power. This function uses in arithmetic and trigonometric operations.
LN (n)The LN(n) function shows the natural logarithm of the given value (n).
LOG (n)The LOG() function returns the natural logarithm of the given value. This function uses in arithmetic and trigonometric operations.
LOG10 ()The LOG10() function displays the base-10 logarithm of the given value.
LOG2 ()The LOG2() function shows the base-2 logarithm of the given value. This function uses in arithmetic and trigonometric operations.
PI ()The PI() function returns the PI value. The pi value has a constant or default value in the mathematical operation.
POW ()The POW() function displays the specific power of the given value. This function uses in arithmetic and trigonometric operations.
POWER () The POWER() function shows the specific power of the given value. This function uses in arithmetic and trigonometric operations.
RADIANS()The RADIANS() function returns given value converts into radians value.
RAND()The RAND() function displays a random value that belongs to a floating-point. This function uses in arithmetic operations.
SIGN (n)The SIGN() function shows the sign of the given value (n).  This value depends on the negative (-1), zero (0), or positive (1). This function does not display the original value of the data.
SIN (n)The SIN(n) function returns the sine of a given value (n). This function works on the angle of the trigonometry operation.
SQRT (n)The SQRT(n) function displays the square root of the given value (n). This function uses in arithmetic and trigonometric operations.
TAN (n)The TAN(n) function displays the tangent of the given value (n). This function works on the angle of the trigonometry operation.

Examples of the MySQL Math Function

The math function operates in arithmetic, trigonometric and other mathematical operations. This function shows the functional values of the given data. The math function provides logarithm, square, squarer root, power, etc. This function determines sin, tan, cos, cot, and other trigonometric functions.

Examples of the basic function and its output

MySQL math function returns the pi value, square value, square root value, power of the required value. You can use a single math function or many math functions in a single query.

Example

MySQL math function returns the constant value of the "PI" function. You need to select the pi function. This function does need to include any value in the function.

mysql> select PI();

OUTPUT

MySQL Math Function

The pi function output returns the "3.14" value. This value uses in arithmetic and trigonometric operations.

Example

The given an example uses five functions to operate numerical value. This query works with square root, square and 5th power of the required value. Here, you operate the absolute value and a round number of the value.

mysql> select SQRT(4), power(4, 2), pow(4, 5), ABS(-4.213), round(3.99);

OUTPUT

MySQL Math Function

The above math functions return five functions output. This output needs to use a specific value. The first two column shows square root and square of the "4" value. The third column returns the 5th power of the "4" value. The fourth column function removes positive and negative signs and returns an only value.

Examples of the logarithmic function and its output

Execute logarithmic math function with its value. The log uses base 10, base 2, and natural base with the value. You can see the difference between logarithmic values. This function contains a "10" value in the required log.

mysql> select LOG(10), LOG10(10), LOG2(10), ln(10);

OUTPUT

MySQL Math Function

The above image shows you different log functions with the same value. The first and last columns show the natural log value. The second column shows base 10 log values. The third column shows the base2 log value.

Examples of the trigonometric function and its output

The trigonometric math function returns the side of the angle and arc of the value. Mysql math function provides SIN, COS, TAN, COT functions. Each function shows several values of the same angle.

Example

The example uses multiple operators or functions in a single query. This function contains a "30" value in the required log.

Mysql> select sin(30), cos(30), cot(30), tan(30);

OUTPUT

MySQL Math Function

The output table returns the value of the trigonometric function. You can get the sin, cos, cot, and tan output with 30 angles in the table. Each column displays a different arc value of the same angle.

Example

Execute the ATAN function with value. You can use two functions to get the arctangent of the data. This function contains 2 and 3 data.

Mysql> select ATAN2(2 , 3), ATAN(3, 2);
OR
Mysql> select ATAN(2 , 3), ATAN(3, 2);

OUTPUT

MySQL Math Function

This output image shows two arctangents with swapping numbers. The same number swaps in the same ATAN operator. This operator returns different output values in the table.

Examples of the arithmetical operations and their output

The math function supports addition, subtraction, division, and multiplication operations. You do not need a special function. The mod() function provides a reminder of the division. You can use select keywords, values and operators to get output.

Example

MySQL functions use an operator and two values to operate mathematical operations. The query uses addition (+), subtraction (-), division (/), and multiplication (*) operators. Here, the example uses 5 and 3 as the first value and second value, respectively.

Mysql> select 5 + 3, 
              5 - 3, 
              5 * 3, 
              5 / 3;

OUTPUT

MySQL Math Function

You can see the output values of the mathematical operations. The columns show 8, 2, 15, and 1.6667 values in the table.

Example

Execute mathematical operations using basic operators in the MySQL interface. The multiple operations combine and use in a single query.

Mysql> select 8 + 3 / 2 * 4 - 1;

OUTPUT

MySQL Math Function

The output returns values of the arithmetic operations. You can operation multiple operators simultaneously and get the 13.0000 value.

Example of the mathematical operations and their output

You can combine several arithmetical and trigonometric functions for mathematical operation.  This example uses the pi value with sin(45) and the division operator. Execute the following math function with value.

Mysql> select pi() * sin(45) / 10;

OUTPUT

MySQL Math Function

The above image returns the output of the given math function. The sin(45) multiplies with the pi value and is divided by 10. The MySql returns the "0.2673" value in the output table.