T Sql 简明教程

T-SQL - Numeric Functions

MS SQL Server数值函数可以对数值数据进行操作,并将返回数值数据。

MS SQL Server numeric functions can be applied on numeric data and will return numeric data.

以下是带示例的数值函数列表。

Following is the list of Numeric functions with examples.

ABS()

对于数值表达式,绝对值将作为输出。

Absolute value will come as output for numeric expression.

Example

以下查询将给出绝对值。

The following query will give the absolute value.

Select ABS(-22)

ACOS()

反正弦值将作为指定数值表达式的输出。

Arc cosine value will come as output for the specified numeric expression.

Example

以下查询将给出0的反正弦值。

The following query will give the arc cosine value of 0.

Select ACOS(0)

ASIN()

反余弦值将作为指定数值表达式的输出。

Arc sine value will come as output for the specified numeric expression.

Example

以下查询将给出0的反余弦值。

The following query will give the arc sine value of 0.

Select ASIN(0)

ATAN()

弧正切值将作为指定的数字表达式的输出。

Arc tangent value will come as output for the specified numeric expression.

Example

以下查询将给出一个弧切 0 的数值。

The following query will give the arc tangent value of 0.

Select ATAN(0)

ATN2()

特定数值表达式的值将作为输出值以所有象限上的弧切值给出的。

Arc tangent value in all four quadrants will come as output for the specified numeric expression.

Example

以下查询将给出一个 0 的所有四个象限内的弧切值。

The following query will give the arc tangent value in all four quadrants of 0.

Select ATN2(0, -1)

可以将 CUSTOMERS 表视为包含以下记录。

Consider the CUSTOMERS table having the following records.

ID  NAME       AGE       ADDRESS             SALARY
1   Ramesh     32        Ahmedabad           2000.00
2   Khilan     25        Delhi               1500.00
3   kaushik    23        Kota                2000.00
4   Chaitali   25        Mumbai              6500.00
5   Hardik     27        Bhopal              8500.00
6   Komal      22        MP                  4500.00
7   Muffy      24        Indore              10000.00

BETWEEN()

如果给出的两个表达式之间存在值域,它将成为一个输出。

If the values exist between given two expressions then those will be come as output.

Example

以下查询将给出以下输出。

The following query will give the following output.

SELECT salary from customers where salary between 2000 and 8500

Output

salary
2000.00
2000.00
6500.00
8500.00
4500.00

MIN()

给定表达式的最小值将作为输出。

Minimum value will come as output from the given expression.

Example

以下查询将给出一个针对客户表中给定的“工资”表达式的“1500.00”。

The following query will give '1500.00' for the given 'salary' expression from the customers table.

Select MIN(salary)from CUSTOMERS

MAX()

给定的表达式的最大值将作为输出。

Maximum value will come as output from the given expression.

Example

以下查询将给出针对客户表中给定的“工资”表达式的“10000.00”。

The following query will give '10000.00' for the given 'salary' expression from the customers table.

Select MAX(salary)from CUSTOMERS

SQRT()

给定数值表达式的平方根将作为输出。

Square root of the given numeric expression will come as output.

Example

以下查询将给出一个针对 4 的数值表达式的 2。

The following query will give 2 for the given 4 numeric expression.

Select SQRT(4)

PI()

PI 值将作为输出。

PI value will come as output.

Example

以下查询将给出一个 3.14159265358979 针对 PI 值。

The following query will give 3.14159265358979 for the PI value.

Select PI()

CEILING()

四舍五入小数后的给定值将作为输出,这将是下一个最高值。

Given value will come as output after rounding the decimals which is the next highest value.

Example

以下查询将给出一个针对 123.25 值的 124。

The following query will give 124 for the given 123.25 value.

Select CEILING(123.25)

FLOOR()

四舍五入后给定值将作为输出,它将小于或等于表达式。

Given value will come as output after rounding the decimals which is less than or equal to the expression.

Example

以下查询将给出一个针对 123.25 值的 123。

The following query will give 123 for the given 123.25 value.

Select FLOOR(123.25)

LOG()

给定表达式的自然对数将作为输出。

Natural logarithm of the given expression will come as output.

Example

以下查询将给出一个针对给定值 1 的 0。

The following query will give 0 for the given 1 value.

Select LOG(1)