0
select di.seq, di.node , di.edge , di.cost, a.geom
from pgr_dijkstra(
    'select id, target, source, sum(cost) from pedroad', 
     array(select get_source2('location1'))
     ,array(select get_target2('test4'))
     ,false) as di, 
    pedroad a
    where di.node = a.source;
error: column "pedroad.id" must appear in the GROUP BY clause or be used in an aggregate function

我应该如何使用group by

4

1 回答 1

0

您作为第一个参数传递的 SQL 字符串中至少有一个语法错误:sum(cost)是一个聚合函数,因此列表中的所有其他列SELECT必须出现在 GROUP BY 子句中或用于聚合函数- 就像错误消息说的那样.

这将修复语法错误:

SELECT di.seq, di.node, di.edge, di.cost, a.geom
FROM   pgr_dijkstra('select id, target, source, sum(cost) from pedroad
                     group by 1,2,3'
                  , array(select get_source2('location1'))
                  , array(select get_target2('test4'))
                  , false) di 
JOIN   pedroad a ON di.node = a.source;

但目前还不清楚你实际上想如何总结......

如果id正好是PK的pedroad,你可以简化为而已group by 1
解释:

于 2016-12-03T15:24:42.990 回答