Constant mathematical functions in SQL

Source: Internet
Author: User
Tags mathematical functions rand random seed

--1 RAND () returns a random value from 0 to 1, the return value is different if no random seed is specified, and the same random value if the specified seed is the same
SELECT RAND ()
SELECT RAND ()
SELECT RAND (100)
SELECT RAND (100)


--Using Time (nanosecond) as a random seed drive
SELECT RAND (DATEPART (Ns,getdate ()))

--2 CEILING () Rounding of floating-point numbers, returning the maximum value, positive floating-point decimal one bit, negative floating-point decimal
SELECT CEILING (9.99999)
SELECT CEILING (-9.000001)

--3 floor () Rounding of floating-point numbers, returning the minimum integer, positive floating-point decimal, negative floating-point decimal into a
SELECT Floor (9.0000001)
SELECT Floor (-9.999999)

--4 ROUND () rounds a floating-point number, controlling the exact digits of the decimal point according to the second parameter
SELECT ROUND (4.444,2)
SELECT ROUND (4.445,2)

--5 ABS () take absolute value
SELECT ABS (-2)
SELECT ABS (2)
SELECT ABS (0)

--6 Power () takes the power value of an expression
SELECT POWER (2,5) --2^5
SELECT POWER (32,1.0/5) --32 open for 5 times

--7 sign () If a positive number returns 1, if a negative number is returned-1, if 0 is returned 0
SELECT sign (-2)
SELECT sign (2)
SELECT sign (0)

--8 SQRT (), requires that the number must be a positive integer
SELECT SQRT (16)


SELECT SQRT (-16)

Constant mathematical functions in SQL

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.