Assuming that you've got two layers:
Clusters
, that holds all your points, each one identified as belonging to a specific cluster by means of an attribute namedcluster_id
;Center_points
with as many points as clusters you've created, and each of them representing the mean coordinates of the cluster, again identified by means of an attribute named"cluster_id"
.
You can create a "Virtual layer" through Layer > AddCreate Layer > Add/EditCreate Virtual Layer
with the following code:
SELECT
p.cluster_id,
avg(st_distance(c.geometry, p.geometry))
FROM
Center_points p,
Clusters c
WHERE
p.cluster_id = c.cluster_id
GROUP BY
p.cluster_id;
Anyway, beware the CRS of both layers, which should be the same and with projected coordinates, so the rendered results are in meters.