MySQL (7)

Source: Internet
Author: User

MySQL (7)
1. mathematical functions

(1) absolute value function (ABS (x) and return the circumference rate function PI

ABS (X) returns the absolute value of X

Select abs (2), abs (-3.3), abs (1-9 );

Select pi ();

(2) square root function SQRT (x) and evaluate the remainder function MOD (x, y)

Select SQRT (9), SQRT (40), SQRT (-49 );

Select MOD (45.5), MOD (), MOD (6 );

(3) obtain the integer functions CEIL (x), CEILING (x) and FLOOR (x)

CEIL (x) and CEILING (x) have the same meaning. The return value is a minimum integer not less than x, and the return value is converted to a BIGINT.

Select CEIL (-3.35), CEILING (3.35 );

Use FLOOR (x) To return the maximum integer not greater than x. The return value is converted to a BIGINT.

Select floor (-3.35), floor (3.35 );

(4) functions RAND () and RAND (x) for obtaining random numbers)

RAND (x) returns a random floating point number v in the range of 0-1. If an integer parameter x is specified, it is used as the seed value to generate a recurring series.

Select RAND (), RAND ();

Select RAND (10), RAND (10 );

(5) Rounding functions ROUND (x), ROUND (x, y), and TRUNCATE (x, y)

ROUND (X) returns an integer closest to x, rounding x

Select round (-1.14), ROUND (-1.67), ROUND (1.14), ROUND (1.67 );

ROUND (x, y) returns the number close to x and retains the y digit after the decimal point. If y is negative, the x value is retained to the y digit on the left of the decimal point.

Select round (1.38, 1), ROUND (1.38, 0), ROUND (232.38,-1), ROUND (232.38,-2 );

TRUNCATE (x, y) returns the number rounded to the y digit after the decimal point. If y is 0, no decimal point or decimal point is returned. If y is a negative number, the system truncates all the low positions after the start of the y decimal point on the left of x.

Select trunacate (1.31, 1), TRUNCATE (1.99, 1), TRUNCATE (1.99, 0)

 

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.