Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQL Server中获取0.00十进制值_Sql_Sql Server - Fatal编程技术网

在SQL Server中获取0.00十进制值

在SQL Server中获取0.00十进制值,sql,sql-server,Sql,Sql Server,我在SQL Server中有以下查询 SELECT SUM(issue_count) AS incent_issued, SUM(redeem_count) AS incent_redeemed, CAST(SUM(redeem_count) / NULLIF(SUM(issue_count), 0) AS decimal(18, 2)) AS incent_redemption_rate FROM incent_summary 我得到以下输出: incent

我在SQL Server中有以下查询

SELECT
    SUM(issue_count) AS incent_issued, 
    SUM(redeem_count) AS incent_redeemed,
    CAST(SUM(redeem_count) / NULLIF(SUM(issue_count), 0) AS decimal(18, 2)) AS incent_redemption_rate
FROM
    incent_summary
我得到以下输出:

incent_issued   incent_redeemed incent_redemption_rate
-------------------------------------------------------
53742                  7205            0.00

为什么我的激励兑换率为0.00?我希望它是0.13。

SQL Server进行整数除法,因此
1/2
0
,而不是
0.5
。我发现最简单的解决办法是乘以
1.0

SUM(redeem_count) * 1.0/NULLIF(SUM(issue_count), 0)

请注意,您将在除法后转换为十进制,因此转换对整数除法没有影响。

SQL Server进行整数除法,因此
1/2
0
,而不是
0.5
。我发现最简单的解决办法是乘以
1.0

SUM(redeem_count) * 1.0/NULLIF(SUM(issue_count), 0)
请注意,您将在除法后转换为十进制,因此转换对整数除法没有影响