Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the digital functions in MySQL

Shulou Source: shulou.com Published: 2022-06-01 02:36:46 11月15日 Update

This article mainly introduces what are the digital functions in MySQL, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Numeric function

1. ABS (x) returns the absolute value of x

SELECT ABS (- 1);-returns 1

2. AVG (expression) returns the average of an expression, and expression is a field.

SELECT AVG (age) FROM student

3. CEIL (x) / CEILING (x) returns the smallest integer greater than or equal to x

SELECT CEIL (1.5); SELECT CEILING (1.5);-return 2

4. FLOOR (x) returns the largest integer less than or equal to x

SELECT FLOOR (1.5);-return 1

5. EXP (x) returns to the x power of e

SELECT EXP (3);-calculates the third power of e and returns 20.085536923188

6. GREATEST (expr1, expr2, expr3, …) Returns the maximum value in the list

SELECT GREATEST (3, 12, 34, 8, 25);-returns the maximum value 34 in the following list of numbers

7. LEAST (expr1, expr2, expr3, …) Returns the minimum value in the list

SELECT LEAST (3, 12, 34, 8, 25);-returns the minimum value of 3 in the following list of numbers

8. LN returns the natural logarithm of a number

SELECT LN (2);-returns the natural logarithm of 2: 0.6931471805599453

9. LOG (x) returns the natural logarithm (the logarithm based on e)

SELECT LOG (20.085536923188);-returns 3

10. MAX (expression) returns the maximum value in the field expression

SELECT MAX (age) AS maxAge FROM Student;---- age maximum

11. MIN (expression) returns the maximum value in the field expression

SELECT MIN (age) AS minAge FROM Student;---- age minimum

12. POW (x ~ () y) / POWER (x ~ ()) returns x to the y power.

SELECT POW (2, 3); SELECT POWER (2, 3);-returns 2 to the third: 8

13. RAND () returns a random number from 0 to 1

SELECT RAND ();-returns a random number from 0 to 1. If there is a number in (), if RAND (x), x is the same, the return value is the same.

14. ROUND (x) returns the integer closest to x

SELECT ROUND (1.23456);-returns 1

15. SIGN (x) returns the symbol of x, where x is negative, 0, and positive returns-1, 0, and 1, respectively.

SELECT SIGN (- 10);-return-1

16. SQRT (x) returns the square root of x

SELECT SQRT (25);-returns 5

17. SUM (expression) returns the sum of the specified fields

SELECT SUM (age) AS totalAage FROM Student;---- returns the sum of age

18. TRUNCATE (xQuery y) returns the value x reserved to the decimal point (the biggest difference from ROUND is that it is not rounded)

SELECT TRUNCATE (1.23456);-return 1.234 Thank you for reading this article carefully. I hope the article "what are the digital functions in MySQL" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Number maximum maximum minimum field logarithm article function integer nature same sum random number rounded value interest at the same time decimal decimal point average Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia MySQL OPPO Reno Apple