Mathematical functions
1, Calculate absolute value ABS
The ABS function calculates an absolute value (except for the bit data type) for a numeric expression result, which returns an integer.
Syntax structure:
ABS (numeric expression)
Return value: Data that is consistent with a numeric expression type
Example:
SELECT ABS ( -1) --Output 1
2. Get greater than or equal to the minimum integer value celling
The ceiling function returns the smallest integer value that is greater than or equal to the numeric expression (except for the bit data type). Commonly known as the ceiling function, as far as possible to the large rounding.
Syntax structure:
CEILING (numeric expression)
Return value: Data that is consistent with the type of the numeric expression.
Example:
SELECT celling (123.1) --Output 124
3. Get the maximum integer value less than or equal to floor
The floor function returns the maximum integer value that is less than or equal to the numeric expression (except for the bit data type). Commonly known as the floor function, as far as possible to small rounding.
Syntax structure:
Floor (numeric expression)
return value:
Data that is consistent with the type of the numeric expression.
Example:
SELECT Floor (123.9999) --Output 123
4. Get random number Rand
The RAND function returns a random floating-point number from 0 to 1.
Syntax structure:
Rand ([seed])
The seed in the syntax is a seed value, an expression of an integer type (tinyint, smallint, int), and calling Rand repeatedly with the specified seed value will return the same result.
Without specifying a seed value, the RAND function randomly produces the result.
return value:
A floating-point number between 0 and 1.
Example:
SELECT Rand () --Output 0.36925407993302
5. Get the specified length and accuracy round
The round function rounds a numeric expression to a specified length and precision.
Syntax structure:
Round (numeric_expression, length[, function])
Parameter description:
Numeric_rxpression: An expression of an exact or approximate numeric type, except for the bit data type.
Length: Rounding Precision. Length must be tinyint, smallint, or int. If length is an integer, the numeric_expression is rounded to the number of decimal digits specified by length. If length is negative, rounds the left part of the decimal point to the length specified by length numeric_expression.
Function: The type of action to perform. The function must be tinyint, smallint, or int. If function is omitted or its value is 0 (the default), Numeric_Expression is rounded. If a value other than 0 is specified, the numeric_expression is truncated.
Return value: A number of the same type as numeric_expression.
Example:
SELECT Round (123.456789,3)-output 123.457000 accurate to 3 digits after the decimal point
6. Degrees
Returns the angle corresponding to radians
SELECT DEGREES (0.6)--34.377467707849391000
7. PI
return PI float
SELECT PI () --3.14159265358979
8. POWER
Returns a value that specifies the power of the specified expression.
SELECT Power (2,10) --1024
9. SQUARE
Returns the square of the specified floating-point value.
SELECT Square (5) --25
10, SQRT
Returns the square root of the specified floating-point value.
SELECT SQRT (+) --5
11. EXP
Returns the exponential value of the specified float expression.
12. SIN ASIN
returns the trigonometric sine of the specified angle (in radians) in an approximate number (float) expression.
13. COS ACOS
14, TAN ATAN ATN2
15. COT
16. LOG LOG10
17. Sign
18, RADIANS
SQL Server Math functions