【问题标题】:How to calculate percentage with a SQL Server statement?如何使用 SQL Server 语句计算百分比?
【发布时间】:2020-10-17 17:33:22
【问题描述】:

【问题讨论】:

  • 请避免发布图片。以文本形式发布。还包括您的要求、计算公式等

标签: sql-server count percentage


【解决方案1】:

除以总数即可得到百分比值。

尝试以下方法:

select top 5 country, Count(country) as COUNT_COUNTRY, cast(count(country)*100.0/(select count(1) from Sales) as numeric(5,2)) as [%age]
from Sales
group by country
order by COUNT_COUNTRY desc

【讨论】:

    猜你喜欢
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    相关资源
    最近更新 更多