计算百分比变化返回0

时间:2020-01-02 10:04:21

标签: sql-server tsql

我试图找到float的百分比变化,但是查询返回0.00

SELECT CAST(((SELECT 115301-(SELECT 114256))/(SELECT 114256))*100 AS DECIMAL(18,2))

在这里我想念什么吗?我应该在哪里编辑SQL?

2 个答案:

答案 0 :(得分:1)

尝试以下操作即可

SELECT CAST(CAST((115301-114256) AS FLOAT)/114256*100 AS DECIMAL(18,2))

答案 1 :(得分:0)

尝试一下:

SELECT CAST(((SELECT 115301.00- (SELECT 114256.00))/(SELECT 114256.00))*100 AS DECIMAL(18,2))

或将数字强制转换为浮点数或十进制

SELECT CAST(((SELECT cast(115301 AS DECIMAL(18,2)) - (SELECT cast(114256 AS DECIMAL(18,2))))/(SELECT cast(114256 AS DECIMAL(18,2))))*100 AS DECIMAL(18,2))