我目前正在处理一个查询,该查询应返回按与给定点的接近程度排序的 CartoDB 表(即新表)的子集。我想在地图上显示与最近的、次近的等相对应的标签,并想通过在新列中使用 PostgreSQL row_number() 方法来捕获它:
SELECT
*,
ST_Distance(
ST_GeomFromText('Point(-73.95623080000001 40.6738101)', 4326)::geography,
the_geom::geography
) / 1609 AS dist,
row_number() OVER (ORDER BY dist) as rownum
FROM locations
WHERE ST_Intersects(
ST_GeomFromText(
'Point(-73.95623080000001 40.6738101)', 4326
),
the_geom
)
ORDER BY dist ASC
但是,当我尝试这样做时,CartoDB/PostgreSQL 返回以下错误:
Error: column "dist" does not exist
关于更好的方法或我遗漏的任何建议?