I would like to compute cluster of points and, for each cluster to get the sum of a specific attribute (let say, the sum of the score of each point in the cluster)
I already managed to build clusters using ST_ClusterWithin
but I cannot compute the sum.
Here is what I tried :
SELECT sum(score), unnest(ST_ClusterWithin(coordinates, 0.1)) AS cluster
FROM locations
GROUP BY cluster;
But I get the following error ERROR: aggregate functions are not allowed in GROUP BY
If I remove the GROUP BY
, I get the sum of the score for all locations, which is not what I want (I want the sum for locations in the cluster)