如何在 SQL 中计算带小数的百分比? [英] How do I calculate percentages with decimals in SQL?

查看:16
本文介绍了如何在 SQL 中计算带小数的百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SQL 中将其转换为小数?下面是等式,我得到的答案是 78(整数),但真正的答案是 78.6(带小数)所以我需要显示这个,否则报告不会达到 100%

How can i convert this to a decimal in SQL? Below is the equation and i get the answer as 78 (integer) but the real answer is 78.6 (with a decimal) so i need to show this as otherwise the report won't tally up to 100%

(100 * [TotalVisit1]/[TotalVisits]) AS Visit1percent

推荐答案

convert(decimal(5,2),(100 * convert(float,[TotalVisit1])/convert(float,[TotalVisits]))) AS Visit1percent

丑陋,但它有效.

这篇关于如何在 SQL 中计算带小数的百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆