2012-10-03 46 views
1

這些數據可免費使用美國國稅局爲收入數據郵政編碼爲2008年。如何在給定MySQL返回數的情況下找到平均AGI?

A00100是經調整的總收入(aka AGI),agi_class是調整總收入的大小。範圍從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_class的退稅數量。

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中執行此操作?謝謝!

回答

2
select zipcode, 
     avg(A00100) as average_income 
from taxbyzip2008 
group by zipcode 
+0

感謝您的回覆。但是這並沒有考慮到每個agi_class的回報數量。既然他們並不都是平等的,那麼在這個例子中,第7類回報的數量與7477回報在這個比agi_class 2中僅有2521更重要嗎? – Edward

+1

如果您想在平均計算中計算所涉及的退貨數量,請編輯您的問題並添加您希望計算的方式。 –

+0

我更新了問題。謝謝! – Edward

相關問題