SQL Server EXP 函数是一个数学函数,用于返回 E 的给定浮点数值的幂,其中 E 是欧拉数,约等于 2.71828。例如,如果我们指定表达式为 EXP(2)。这意味着 e² ==> 2.718² ==> 7.38。
EXP 函数的语法如下所示。
SELECT EXP (Float_Expression) FROM [Source]
SQL Server EXP 函数示例
EXP 函数可用于计算欧拉数 E 的幂。在此示例中,我们将使用不同的数据(正值和负值)来检查相同的值并显示输出。
DECLARE @i float SET @i = 2 SELECT EXP(@i)AS [Exponent Result 1] -- Calculating Exp directly SELECT EXP(1) AS [Exponent Result 2] SELECT EXP(62.9876) AS [Exponent Result 3] SELECT EXP(108.65 + 231.1237 - 213.32 + 15.09) AS [Exponent Result 4] -- Calculating Exp for Negative Values SELECT EXP(-1) AS [Exponent Result 5] SELECT EXP(-6.579) AS [Exponent Result 6]

以下代码行有助于声明浮点变量并为其分配随机值。
DECLARE @i float SET @i = 2
接下来,我们计算 @i 的指数值。我们还使用 SQL Server 中的 ALIAS 列将结果命名为“Exponent Result 1”。
SELECT EXP(@i)AS [Exponent Result 1]
在下面的语句中,我们直接在正浮点值上使用了 EXP 函数。这里,EXP(1) 意味着 e1 ==> 2.7181 ==> 2.718。
SELECT EXP(1) AS [Exponent Result 2] SELECT EXP(62.9876) AS [Exponent Result 3] SELECT EXP(108.65 + 231.1237 - 213.32 + 15.09) AS [Exponent Result 4]
接下来,我们直接在负浮点值上使用了 SQL EXP 函数。
SELECT EXP(-1) AS [Exponent Result 5] SELECT EXP(-6.579) AS [Exponent Result 6]
SQL 指数函数示例 2
在此 数学函数 示例中,我们将使用 EXP 函数计算 [Tax Amount] 列中所有记录的 E 的幂。
SELECT [EnglishProductName]
,[Color]
,[StandardCost]
,[ListPrice]
,[DealerPrice]
,[SalesAmount]
,[TaxAmt]
,EXP([TaxAmt]) AS [Tax_Exponent result]
FROM [Prod Sales]
