I have two tables in PostgreSQL 13:
hexbin
table with geom field (red)sites
table with geom field (blue)
I want to return a table with the hexbin geometries and a total count of where the sites fall within the hexbin (counting site centers in hexbins).
The following code does appear to return me what I require:
SELECT hexbin.gid, hexbin.geom, count(*) AS site_total
FROM sites, hexbin
WHERE ST_intersects(hexbin.geom, (ST_PointOnSurface(sites.geom)))
GROUP BY hexbin.gid
Can this approach be improved?
From looking at other samples and my previous experience with SQL Server Spatial, should I be incorporating a join to improve performance?
JOIN
already. It's good practice to use the verboseJOIN
syntax, though. Maybe useCOUNT(sites.*)
.