I'm a novice with PostGIS and am currently working on a lab assignment where I have two geometric tables - one containing demographic data by blockgroup (blockgrp2010) while the other identifies various neighborhoods (nbo_hood). I'm trying to write a query that lists the population for each neighborhood. For now, I'm assuming that if the centroid of the blockgroup is inside the neighborhood, then all the population lies within that neighborhood. I drafted the query below:
select nbo_hood.name, blockgrp2010.pop10
from blockgrp2010
inner join nbo_hood on ST_Within ((ST_Centroid (blockgrp2010.geom)), nbo_hood.geom)
group by nbo_hood.name, nbo_hood.geom, blockgrp2010.pop10;
This returns a table listing the neighborhoods and corresponding population for each blockgroup. However, many of the neighborhoods are listed under multiple rows with a different population assigned (obviously because there are multiple blockgroups within the neighborhood).
How do I modify the above query (or should I start from scratch) to list each neighborhood only once with the population sum of all blockgroups?
I've tried variations of the SUM function with the SELECT statement but nothing as worked.