【发布时间】:2014-06-18 22:18:56
【问题描述】:
我需要计算两个数字之间的增长百分比。 在下面的示例中,起始值是第一个,当前值是第二个。 当我尝试以下查询时,结果不符合我的预期。
SELECT ( CAST (68 as float) / CAST (1 as float) * 100)
--current value 68, start value 1, the percentage of growth is 68%
--MSSQL is giving the result 6800, which is 100 times too high
SELECT ( CAST (30 as float) / CAST (10 as float) * 100)
--current value 30, start value 10, the percentage of growth is 300%
--MSSQL is giving the result 300, which makes sense
SELECT ( CAST (20 as float) / CAST (40 as float) * 100)
--current value 20, start value 40, the percentage of growth is -50%
--MSSQL is giving the result 50, which somewhat makes sense
我应该使用哪个查询来获得每种情况的一致输出,以便我可以使用它在图表中正确显示?
【问题讨论】:
标签: percentage