/ (Division) (Transact-SQL)/ (Division) (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

用一个数除以另一个数(算术除法运算符)。Divides one number by another (an arithmetic division operator).

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

dividend / divisor  

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

参数Arguments

dividenddividend
被除数的数值表达式。Is the numeric expression to divide. dividend 可以是具有数值数据类型类别中任一数据类型(datetime 和 smalldatetime 数据类型除外)的任何有效表达式**********。dividend can be any valid expression of any one of the data types of the numeric data type category, except the datetime and smalldatetime data types.

divisordivisor
除数的数值表达式。Is the numeric expression by which to divide the dividend. divisor 可以是具有数值数据类型类别中任一数据类型(datetime 和 smalldatetime 数据类型除外)的任何有效表达式**********。divisor can be any valid expression of any one of the data types of the numeric data type category, except the datetime and smalldatetime data types.

结果类型Result Types

返回优先级较高的参数的数据类型。Returns the data type of the argument with the higher precedence. 有关详细信息,请参阅数据类型优先级 (Transact-SQL)For more information, see Data Type Precedence (Transact-SQL).

如果整数的 divisor 除以整数的 dividend,其结果是一个整数,小数部分被截断****。If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

备注Remarks

/ 运算符返回的实际值是用第一个表达式除以第二个表达式所得的商。The actual value returned by the / operator is the quotient of the first expression divided by the second expression.

示例Examples

以下示例将使用除法算术运算符来计算 Adventure Works CyclesAdventure Works Cycles 中销售人员的每月销售目标。The following example uses the division arithmetic operator to calculate the sales target per month for the sales people at Adventure Works CyclesAdventure Works Cycles.

-- Uses AdventureWorks  
  
SELECT s.BusinessEntityID AS SalesPersonID, FirstName, LastName, SalesQuota, SalesQuota/12 AS 'Sales Target Per Month'  
FROM Sales.SalesPerson AS s   
JOIN HumanResources.Employee AS e   
    ON s.BusinessEntityID = e.BusinessEntityID  
JOIN Person.Person AS p   
    ON e.BusinessEntityID = p.BusinessEntityID;  

以下为部分结果集。Here is a partial result set.

  
SalesPersonID FirstName    LastName          SalesQuota  Sales Target Per Month  
------------- ------------ ----------------- ----------- ------------------  
274           Stephen      Jiang             NULL        NULL  
275           Michael      Blythe            300000.00   25000.00  
276           Linda        Mitchell          250000.00   20833.3333  
277           Jillian      Carson            250000.00   20833.3333  
  

示例:Azure Synapse Analytics(SQL 数据仓库)Azure Synapse Analytics (SQL Data Warehouse)并行数据仓库Parallel Data WarehouseExamples: Azure Synapse Analytics(SQL 数据仓库)Azure Synapse Analytics (SQL Data Warehouse) and 并行数据仓库Parallel Data Warehouse

以下示例使用除法算术运算符来计算每位员工的休假时间与病假时间的简单比值。The following example uses the division arithmetic operator to calculate a simple ratio of each employees' vacation hours to sick hours.

-- Uses AdventureWorks  
  
SELECT FirstName, LastName, VacationHours/SickLeaveHours AS PersonalTimeRatio  
FROM DimEmployee;  
  

另请参阅See Also

数据类型 (Transact-SQL) Data Types (Transact-SQL)
内置函数 (Transact-SQL) Built-in Functions (Transact-SQL)
运算符 (Transact-SQL) Operators (Transact-SQL)
SELECT (Transact-SQL) SELECT (Transact-SQL)
WHERE (Transact-SQL) WHERE (Transact-SQL)
/=(除法赋值)(Transact-SQL) /= (Division Assignment) (Transact-SQL)
复合运算符 (Transact-SQL)Compound Operators (Transact-SQL)