Php 在MySQL中,给定返回次数,如何找到平均AGI?

Php 在MySQL中,给定返回次数,如何找到平均AGI?,php,mysql,math,statistics,Php,Mysql,Math,Statistics,该数据可从美国国税局免费获得2008年按邮政编码划分的收入数据 A00100是调整后的总收入(又名AGI),AGI_类是调整后总收入的大小。范围从1到7: 1 = 'Under $10,000' 2 = '$10,000 under $25,000' 3 = '$25,000 under $50,000' 4 = '$50,000 under $75,000' 5 = '$75,000 under $100,000' 6 = '$100,000 under $200,000' 7 = '$200

该数据可从美国国税局免费获得2008年按邮政编码划分的收入数据

A00100是调整后的总收入(又名AGI),AGI_类是调整后总收入的大小。范围从1到7:

1 = 'Under $10,000'
2 = '$10,000 under $25,000'
3 = '$25,000 under $50,000'
4 = '$50,000 under $75,000'
5 = '$75,000 under $100,000'
6 = '$100,000 under $200,000'
7 = '$200,000 or more '
“申报数量”是该agi_类别的纳税申报数量

mysql> select A00100,zipcode,agi_class,N1 as 'Number of Returns' from taxbyzip2008 where     zipcode="10021";
+-------------+---------+-----------+-------------------+
| A00100      | zipcode | agi_class | Number of Returns |
+-------------+---------+-----------+-------------------+
|     -954234 | 10021   |         1 |              3589 |
|    43243455 | 10021   |         2 |              2521 |
|   149940475 | 10021   |         3 |              3939 |
|   243853640 | 10021   |         4 |              3936 |
|   262995399 | 10021   |         5 |              3025 |
|   751195421 | 10021   |         6 |              5333 |
| 10677437299 | 10021   |         7 |              7477 |
+-------------+---------+-----------+-------------------+

我需要计算出每个邮政编码的平均调整后总收入。我如何在MySQL中做到这一点?谢谢

谢谢你的回复。但这并没有考虑每个agi_类的退货数量。因为它们并不都相等,所以在本例中,拥有7477个回报的第7类回报的数量在这方面不是比只有2521个回报的agi_第2类回报的权重更大吗?如果你想在平均计算中考虑回报的数量,那么编辑你的问题并添加你想要的计算方式。因此,如何再次计算平均值?将A00100除以每个类别的收益数,计算平均值、中值和标准偏差。对于收入数据,中位数比平均值更重要,因为它给出了第50百分位的收入。标准偏差为您提供了有关每个agi类别的方差范围的信息。数字越大,方差越大。实际上,这意味着agi阶层的收入范围越大。这是如何在MySQL中完成的,还是需要在PHP中完成计算?
select zipcode, 
       avg(A00100) as average_income
from taxbyzip2008 
group by zipcode