我有 sql:
SELECT osm_id, vertex_id
FROM ways
JOIN
(SELECT * FROM shortest_path('
SELECT gid AS id,
source::int4 AS source,
target::int4 AS target,
length::float8 AS cost
FROM ways',
7856,
18774,
false,
false)) AS route
ON
ways.gid = route.edge_id
order by vertex_id
它产生这样的东西:
osm_id;vertex_id
5024380;6223
5024380;6224
5024380;6225
5024380;6226
175339584;6227
5024380;6230
5024380;6231
5024380;6232
38521651;6233
5024380;6234
你可以看到,osm_id 不是唯一的。我osm_id
订购了vertex_id
。我如何只能获得osm_id
由vertex_id
. 我不需要vertex_id
专栏。只需要osm_id
. 我尝试group by
了从句,但这不起作用。闲置查询:
SELECT distinct osm_id
FROM ways
JOIN
(SELECT * FROM shortest_path('
SELECT gid AS id,
source::int4 AS source,
target::int4 AS target,
length::float8 AS cost
FROM ways',
7856,
18774,
false,
false)) AS route
ON
ways.gid = route.edge_id
--group by osm_id
order by vertex_id
给出错误:
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 21: order by vertex_id
^
********** Error **********
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
SQL state: 42P10
Character: 420