SQL Server functions full solution < two > math functions

Source: Internet
Author: User
Tags abs acos asin cos mathematical functions natural logarithm sin square root

Mathematical functions are mainly used to deal with numerical data, the main mathematical functions are: absolute value function, trigonometric functions (including sine function, cosine function, tangent function, cotangent function), logarithmic function, random function and so on. In the case of an error, the math function returns a null value of NULL. This article introduces the functions and usages of various mathematical functions.

1. Absolute function abs (x) and function Pi returning pi ()ABS (x) returns the absolute value of x, Pi () returns the values of pi   Eg:select ABS (2), ABS ( -3.3), ABS ( -33), PI ();The absolute value of a positive number is itself, the absolute value of 2 is 2, the absolute value of the negative is its opposite, and-3.3 is the absolute value of 3.3,-33 is 33. 2. Square root function sqrt (x)SQRT (x) returns the two root of a non-negative x   Eg:select SQRT (9), SQRT (+); 3. Functions for obtaining random functions rand () and rand (x)RAND (x) returns a random floating-point value of V, ranging between 0~1 (that is, 0<=v<=1.0). If you specify an integer parameter x, it is used as the seed value, and the same seed number will produce a repeating sequence.   If the same seed value calls the RAND function multiple times, it returns the same build value. eg:select rand (), RAND (), Rand ();you can see that rand () with no parameters produces a different value each time. eg:select Rand, Rand (TEN), Rand (one);as you can see, when rand (x) 's parameters are the same, the same random number is generated, and the random values produced by the different x are different. 4. Rounding function round (x, y)ROUND (x, y) returns the number close to the parameter x, whose value remains at the Y-bit after the decimal point, and if Y is negative, the X value is preserved to the left Y-bit of the decimal point. eg:select ROUND (1.38,1), ROUND (1.38,0), ROUND (232.38,-1), ROUND (232.38,-2);ROUND (1.38,1) retains one after the decimal point, rounding the result to 1.4;round (1.38,0) retains 0 bits after the decimal point, that is, returns the rounded integer value, ROUND (232.38,-1) and ROUND (232.38,-2) Leave 1 and 2 digits to the left of the decimal point respectively. 5. Symbol function sign (x)sign (x) returns the symbol for the parameter, the value of x is negative, 0, or positive, and the result is 1, 0, or 1, in turn. eg:select sign ( -21), sign (0), sign (+);Sign (-21) return -1,sign (0) return 0,sign (21) return 1 6. Functions that get integers ceiling (x) and floor (x)CEILING (x) returns the smallest integer value not less than X, and floor (x) returns the maximum number of integers not greater than x;eg:select CEILING ( -3.35), CEILING (3.35), Floor ( -3.35), floor (3.35);(1),-3.35 is negative, not less than-3.35 of the smallest integer is-3, not less than 3.35 of the smallest integer value is 4(2),-3.35 is negative, not greater than-3.35 of the smallest integer is-4, not greater than 3.35 of the smallest integer value is 3 7. Power Operation function Power (x, y), SQUARE (x), and exp (×)(i). The POWER (x, y) function returns the result value of the Y-exponent of X;(ii). The square (x) function returns the square of the specified floating-point value x;(iii). The EXP (x) function returns the value after the X-exponentiation of E. Eg:select Power (2,2), Power (2.00,-2), Square (3), Square ( -3), square (0), exp (3), exp ( -3), exp (0); you can see that POWER (2,2) returns 2 squared, and the result is 4;power (2.00,-2) returns 2-2 times, resulting in 0.25;Square (3) returns 3 square, the result is 9;square (-3) returns the square of 3, the result is; Square (0) returns the square of 0, the result is 0;exp (3) returns an e-based 3-square, the result is 20.0855369231877, exp (-3) returns to the base of the E-3 times, the result is 0.0497870683678639;EXP (0) returns the 0-time base of e, with a result of 1. 8. Logarithmic operation log (x) and LOG10 (x)log (x) returns the natural logarithm of x, and the logarithm of x relative to Cardinal E. LOG10 (x) returns the logarithm of the cardinality of X of 10. eg:select Log (3), log (6), LOG10 (1), LOG10 (+), LOG10 ( +);The logarithm definition field cannot be negative, 10 of 0 is 1, so LOG10 (1) Returns the result is 0,10 2 is 100, so LOG10 (100) Returns the result is 2,10 3 is 1000, so LOG10 (1000) Returns the result is 3; 9. Functions Randians (x) and degrees (x) for the conversion of angles and radiansRandians (x) converts the parameter x from an angle to a radian. DEGREES (x) converts the parameter x to an angle with radians. eg:select RADIANS (90.0), RADIANS (180.0), DEGREES (Pi ()/2), DEGREES (Pi ()); 10. Sine function sin (x) and inverse chord function asin (x)sin (x) returns the sine of x, where x is the radian value;ASIN (x) returns the inverse of x, which is the value of sine x, and returns null if X is not in the range 1 to 1. eg:select sin (pi ()/2), Sin (Pi ()), ASIN (1), ASIN (0); 11. Cosine function cos (x) and inverse cosine function acos (x)COS (x) returns the cosine of x, where x is the radian value;ACOS (x) returns the inverse cosine of x, which is the value of cosine x. Returns NULL if X is not within the range of 1 to 1;eg:select cos (0), cos (PI ()), ACOS (1), ACOS (0); 12. Tangent function tan (x), Inverse tangent function atan (x) and cotangent function Cot (x)TAN (x) returns the tangent of x, where x is the given radian value;ATAN (x) returns the inverse tangent of x, which is the value of tangent x;COT (x) returns the cotangent of X. Eg:select Tan (0.3), ROUND (Tan (pi ()/2), 0), ATAN (0.30933624960962325), ATAN (1), cot (0.3), 1/tan (0.3), cot (pi ()/4);

SQL Server functions full solution < two > math functions

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.