如何使用 SQL 服务器语句计算百分比?
How to calculate percentage with a SQL Server statement?
I want to add a column for the percentage of COUNT_COUNTRY values, how to do that in SQL server?
除以总计数得到百分比值。
尝试以下操作:
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
I want to add a column for the percentage of COUNT_COUNTRY values, how to do that in SQL server?
除以总计数得到百分比值。
尝试以下操作:
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