Loading

MySQL Numeric or Mathematical Function Part5

POW Function:- POW Function is used for returning the value of a number raised to the power of another number. This function is similar to the POWER function.

Syntax:- If base = b and exponent = e

POW(b, e)

Example:-

SELECT POW(2, 3);

Output:- 8

POWER Function:- The POWER Function is used for returning a number raised to the power of another number. It is similar to POW() Function.

Syntax:- If base = b and exponent = e

POWER (b, e)

Example:-

SELECT POWER (3, 4);

Output:- 81

RADIANS Function:- RADIANS Function is used for converting numbers from degrees to radians.

Syntax:- RADIANS(number)

Example:-

SELECT RADIANS(30);

Output:- 0.5235987755982988

RAND Function:- RAND Function is used for returning floating point random numbers between 0 and 1. If we will define seed then it will return a repeatable sequence of random numbers.

Syntax:- RAND(seed);

Here the seed is optional.

Example:-

SELECT RAND();

Output:- 0.8532903370012439

SELECT RAND(5);

Output:- 0.40613597483014313

SELECT RAND()*(7-3)+2;

Output:- 5.356127615418404

SELECT FLOOR(RAND()*(7-3)+2);

Output:- either 3 or 2

ROUND Function:- ROUND Function is used for rounding a number from the specified decimal place. If the specified decimal place will not mention or the specified decimal place defines zero then it will round the number nearest integer.

Syntax:- ROUND(n, d);

Where n = number(required) and d= Specified decimal place(optional)

Example:-

SELECT ROUND(137.258, 2);

Output:- 137.26

SELECT ROUND(137.258);

Output:-137

SIGN Function:- The SIGN Function is used for returning positive or negative signs of a number. If the number will be greater than zero then it will return 1 and if the number will be less than zero then it will return -1, and if the number will be equal to zero then it will return 0.

Syntax:- SIGN(number)

Example:-

SELECT SIGN(245.89);

Output:- 1

SELECT SIGN(245.89);

Output:-  -1

SIN Function:- The SIN Function is used for returning the sine value of a given radian value number.

Syntax:- SIN(number)

Example:-

SELECT SIN(5);

Output:-  -0.9589242746631385

SQRT Function:- SQRT Function is used for returning the square root of nonnegative numbers.

Syntax:- SQRT(number)

Example:-

SELECT SIN(144);

Output:- 12

SUM Function:- The SUM Function is used for the addition of two or more numbers. In another word, It calculates a set of values.

Syntax:- SUM(expression)

Example:-

SELECT SUM(4+6+23+56);

Output:- 89

Find the total marks Sohan got in their annual examination.

SELECT SUM(marks) AS TotalMarks FROM students WHERE studentName = “Sohan” AND exam = “annual”;

TAN Function:- TAN Function is used for the tangent value of a given radian number.

Syntax:- TAN(Number)

Example:-

SELECT TAN(2.25);

Output:-  -1.2386276162240966

TRUNCATE Function:- TRUNCATE Function is used for returning truncated or shortened numbers from the specified number of decimal places.

Syntax:- TRUNCATE(number, decimal place)

Example:-

SELECT TRUNCATE(234.7898, 3);

Output:- 234.789

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w