二つのテーブルの結合
SELECT count(gid) AS links, sum(a.cost) AS cost, sum(length) AS length FROM shortest_path( 'SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM <TABLE A> WHERE <...>, false, false ) AS a LEFT JOIN <TABLE B> ON (a.gid = gid)