"MySQL function" MySQL 5.5 starting from scratch sixth chapter

Source: Internet
Author: User
Tags mathematical functions rand square root

Description: This article summarizes from: "MySQL 5.5 Start from scratch" chapter sixth

The functions in MySQL include:

Mathematical functions, String functions, date and time functions, conditional judgment functions, System information functions and cryptographic functions.

Function:

Represents a value that returns a specific relationship to the input parameter value.

First, mathematical functions

The main mathematical functions are: absolute value function, trigonometric function (including sine function, cosine function, tangent function, cotangent function, etc.),

Logarithmic functions, random functions, and so on. (PS: The math function will return NULL if there is an error)

1.1 Absolute Value function abs (x)

Mysql> SELECT ABS (1), ABS ( -1.1), ABS ( -33), +--------+-----------+----------+| ABS (1) | ABS (-1.1) | ABS ( -33) |+--------+-----------+----------+|      1 |       1.1 |       |+--------+-----------+----------+1 row in Set (0.03 sec)

1.2 Returning pi function pi ()

Mysql> SELECT PI (); +----------+| PI ()     3.141593 |+----------+1 row in Set (0.00 sec)

1.3 Square root function sqrt (x)

 PS:SQRT (x) range two root of nonnegative x

Mysql> SELECT SQRT (9), SQRT (Ten), SQRT ( -9), +---------+--------------------+----------+| SQRT (9) | SQRT (Ten)           | SQRT ( -9) |+---------+--------------------+----------+|       3 | 3.1622776601683795 |     NULL |--negative number without square root +---------+--------------------+----------+1 row in Set (0.00 sec)

1.4 Complementary function mod (x, y)

Mysql> Select mod (5,2), mod (7,4), mod (50,8), +----------+----------+-----------+| MOD (5,2) | MOD (7,4) | MOD (50,8) |+----------+----------+-----------+|        1 |        3 |         2 |+----------+----------+-----------+1 row in Set (0.00 sec)

1.5 functions to get integers ceil (x), CEILING (x), floor (x)

 Ps:ceil (x), CEILING (x) have the same meaning

Mysql> SELECT ceil ( -2.26), ceil (2.26), CEILING ( -2.26), CEILING (2.26), +-------------+------------+--------------- -+---------------+| Ceil (-2.26) | Ceil (2.26) | CEILING (-2.26) | CEILING (2.26) |+-------------+------------+----------------+---------------+|          -2 |          3 |             -2 |             3 |+-------------+------------+----------------+---------------+1 row in Set (0.00 sec)

Mysql> SELECT Floor ( -2.26), floor (2.26), +--------------+-------------+| Floor (-2.26) | Floor (2.26) |+--------------+-------------+|           -3 |           2 |+--------------+-------------+1 row in Set (0.00 sec)

1.6 Functions to get random numbers rand () and rand (x)

Ps:a.rand (x) returns a random floating-point value of V, ranging from 0 to 1. If an integer parameter x has been established, it is used as a seed value to produce a repeating sequence.

B. rand () with no parameters has a different random value each time

C. When the rand () parameter is identical, the same random number will be generated, and the random values produced by the different x are different

Mysql> SELECT rand (), RAND (), Rand (), +--------------------+--------------------+--------------------+| RAND ()             | RAND ()             | RAND ()             |+--------------------+--------------------+--------------------+| 0.0917864060884215 | 0.6539400337766298 | 0.9943409813515293 |+--------------------+--------------------+--------------------+1 row in Set (0.00 sec) mysql> SELECT rand (5), Rand (5), Rand (6), +---------------------+---------------------+--------------------+| RAND (5)             | RAND (5)             | RAND (6)            0.40613597483014313 | 0.40613597483014313 | 0.6563190842571847 |+---------------------+------- --------------+--------------------+1 row in Set (0.00 sec)

"MySQL function" MySQL 5.5 starting from scratch sixth chapter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.