相关的前一个问题:
在按值(而不是列)分组后,从组中选择一个随机条目?
我当前的查询如下所示:
WITH
points AS (
SELECT unnest(array_of_points) AS p
),
gtps AS (
SELECT DISTINCT ON(points.p)
points.p, m.groundtruth
FROM measurement m, points
WHERE st_distance(m.groundtruth, points.p) < distance
ORDER BY points.p, RANDOM()
)
SELECT DISTINCT ON(gtps.p, gtps.groundtruth, m.anchor_id)
m.id, m.anchor_id, gtps.groundtruth, gtps.p
FROM measurement m, gtps
ORDER BY gtps.p, gtps.groundtruth, m.anchor_id, RANDOM()
Run Code Online (Sandbox Code Playgroud)
语义:
有两个输入值:
array_of_points
distance
第一段(第1-6行):
第二段(第8-14行):
points
表格内的每个点:从表格中获取一个距离< 的随机(!)groundtruth
点measurement
distance
gtps
表中第三段(第16-19行):
groundtruth
值gtps
:获取所有anchor_id …
sql postgresql postgis query-optimization aggregate-functions