2013-03-09 38 views
1

我有SQL:pgRouting shortest_path得到潮頭osm_id值

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不是唯一的。我neet osm_id訂購vertex_id。我怎樣才能得到唯一osm_idvertex_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 
+0

什麼表不vertex_id從何而來?方式或'路線'/ shortest_path子查詢?來自shortest_path子查詢的 – 2013-03-09 14:22:14

+0

。 – Guntis 2013-03-09 14:30:35

回答

1

試試這個:

SELECT 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 min(vertex_id) 
+0

如果取消註釋'group by osm_id',那麼錯誤是相同的。 – Guntis 2013-03-09 14:21:39

+0

請現在就試試! – www 2013-03-09 14:33:12

+0

作品:)謝謝。 – Guntis 2013-03-09 14:36:34