表达百分比 [英] Expressing percentage

查看:127
本文介绍了表达百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要能够将查询结果中包含的某个字段中每个记录的值除以同一字段中所有值的总和。这将使我能够计算每条记录的整体百分比。结果必须在新字段的同一域中以
表示。



这是:让我们在QueryX的结果中说 - 这是我正在使用的表 -   FieldA中的每条记录必须除以FieldA的总和,然后表示为新的neigbouring ColumnB中的分数/百分比。



我在QueryX中试过这个:



总计:(选择总和(ColumnA)来自QueryX) - 然后在第二个子查询中百分比:([CountOfColumnA / Total])



这个工作过一次,但由于来自QueryX的QueryX,Access因为循环错误而阻止了我。



现在我试图重写它并只在一个子查询中找到答案以避免循环问题。我可以在Excel中轻松完成,但是对于在Access中管理它的表达式和编码知之甚少。



有人可以帮忙吗?



Wilhelm

解决方案

< blockquote>

您好,


您可以尝试以下任一方法:


SELECT FieldA,(SELECT Sum(T1.FieldA)FROM TableName AS T1)AS总计,FieldA /总AS比率来自TableName


或:


SELECT FieldA,DSum(" FieldA"," TableName" ;)AS Total,FieldA /总AS比率来自TableName


希望它有所帮助......


I need to be able to divide the values of each record in a certain field contained in a query result by the sum of all the values in the same field. This will enable me to calculate the percentage that each record is of the whole. The results must be expressed in the same domain in a new field.

That is: Let's say in the results of QueryX - which is the table I am working with -  each record in FieldA must be divided by the sum of FieldA, then expressed as a fraction/percentage in a new, neigbouring ColumnB.

I have tried this in QueryX:

Total: (select sum(ColumnA) from QueryX) - then in a second subquery Percentage:([CountOfColumnA/Total])

This worked once, but Access stopped me with a circular error because of the QueryX from QueryX.

Now I am trying to rewrite it and reach the answer in only one subquery to avoid the circular problem. I can easily do this in Excel, but don't know enough about expressions and coding to manage it in Access.

Can anybody help?

Wilhelm

解决方案

Hi,

You could try either of the following:

SELECT FieldA, (SELECT Sum(T1.FieldA) FROM TableName AS T1) AS Total, FieldA/Total AS Ratio FROM TableName

Or:

SELECT FieldA, DSum("FieldA", "TableName") AS Total, FieldA/Total AS Ratio FROM TableName

Hope it helps...


这篇关于表达百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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