我对SQL还很陌生,只用了一周的postgresql。我有点卡住了...
我正在使用NY数据集(http://workshops.opengeo.org/postgis-intro/about_data.html)。
我需要找到一种方法来列出所有亚洲人口比相应的行政区平均值更高的社区,并显示亚洲人口的百分比。
我考虑了这个:
select name, 100 * sum(c.popn_asian)/(select (avg(popn_asian)) from nyc_census_blocks group by boroname)
from nyc_neighborhoods n, nyc_census_blocks c
where (ST_Contains(n.geom, c.geom) = true )
and (sum(c.popn_asian)) > (select avg(popn_white) from nyc_census_blocks c1 group by c1.boroname)
但是显然在where子句后面不能使用sum函数...我想知道为什么以及如何解决这个问题。
谢谢