问题描述
您好,以下查询会向我提供以下结果。
Hi, below query gives me the result below.
现在我必须创建一个额外的列,计算每月总"每月计数"的百分比每个用户每个状态。例如:12月,
每月计数为2786(mrob批准2785和rsimm批准1),我需要计算每月总数的百分比。 12月,mrob已批准99.96%,而rsimm已批准0.035%。
如下所示
$
如何修改查询?
Now I have to create an additional column calculating the percentage of total 'Monthly count' Per month per user per Status. For Example: In December,
The monthly Count is 2786 (mrob Approved 2785 and rsimm approved 1), I need to calculate the percentage of the total per month. In December, mrob has Approved 99.96% and rsimm has approved 0.035%.
Like these below
How to modify the query?
推荐答案
选择*,[每月计数] * 100.0 / sum([MonthlyCount])时(分区) [月])[百分比]
select *, [Monthly Count] * 100.0 / sum([MonthlyCount]) over (partition by [Month] ) as [Percentage]
来自cte
按...排序
这篇关于SQL查询:计算每个用户每月总计数的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!