select
a.ogc_fid,
a.health,
a.spc_common,
b.neighborhood
from
nyc_2015_tree_census a,
nyc_neighborhoods b
where
st_intersects(a.geom, b.geom)
and a.spc_common ilike '%maple%'
select
a.ogc_fid,
a.health,
a.spc_common,
b.neighborhood
from
nyc_2015_tree_census a
join nyc_neighborhoods b on st_intersects(a.geom, b.geom)
and a.spc_common ilike '%maple%'
with trees as (
select
ogc_fid,
health,
spc_common,
geom
from
nyc_2015_tree_census
where
spc_common ilike '%maple%'
)
select
trees.ogc_fid,
trees.health,
trees.spc_common,
b.neighborhood
from
trees
join nyc_neighborhoods_subdivide b on st_intersects(trees.geom, b.geom)
select
count(a.ogc_fid) filter (
where
a.spc_common ilike '%maple%'
) :: numeric / count(a.ogc_fid) :: numeric as percent_trees,
count(a.ogc_fid) filter (
where
a.spc_common ilike '%maple%'
) as count_maples,
b.neighborhood
from
nyc_2015_tree_census a
join nyc_neighborhoods_subdivide b on st_intersects(a.geom, b.geom)
group by
b.neighborhood