0

我需要在 postgis 上比较一些空间数据,但我需要与另一个表“card_history”中的非几何数据进行比较,女巫包含使用“ST_GeomFromText”函数所需的纬度和经度字段。但是我如何在一个查询中做到这一点?由于我正在研究 php(女巫不相关),因此进行大量查询会非常痛苦......

我正在尝试这样的事情:

SELECT ST_Distance_Sphere
  (ST_GeomFromText('POINT(
      (SELECT DISTINCT ON (userid) long from card_history) 
      (SELECT DISTINCT ON (userid) lat from card_history))',4326),
   ST_GeomFromText('POINT(17.0712215 48.15825)',4326)
  )

但是子查询似乎不能作为“POINT”的参数。请帮忙

4

1 回答 1

3

尝试这个

WITH 
lon AS (
    SELECT DISTINCT ON (userid) AS long from card_history
), 

 lat AS (
     SELECT DISTINCT ON (userid) AS lat from card_history
)

SELECT ST_Distance_Sphere(ST_GeomFromText(

'POINT(' || lon.lon || ' ' || lat.lat || ',4326'),

ST_GeomFromText('POINT(17.0712215 48.15825)',4326))

FROM lon, lat;
于 2013-11-08T12:23:34.417 回答