这有点难以描述,但是我有一个 postgresql 9.1 表(planet_osm_roads)。我的查询是
SELECT
osm_id, name, highway, way, md5(astext(way)) AS md5
FROM planet_osm_roads
WHERE highway IS NOT NULL
AND md5(astext(way)) IN (
SELECT DISTINCT md5(astext(way))
FROM planet_osm_roads
WHERE highway IS NOT NULL
GROUP BY md5
HAVING count(osm_id) > 1
)
ORDER BY osm_id
结果是
osm_id | name | highway | ...way ... | md5
----------+------+---------------+-------...----...--+----------------------------------
-1641383 | | motorway | 010200...CA96...0 | 04b4336b997e7ea9d99208bd487bbe7d
-1641383 | | motorway | 010200...EC3E...0 | ae945148417ada285130c59277c48a25
-1641383 | | motorway | 010200...7BF6...0 | 5c5a1b8ae40c1b7f24e293a012ad2add
23133731 | | motorway_link | 010200...EC3E...0 | ae945148417ada285130c59277c48a25
31309105 | | motorway | 010200...7BF6...0 | 5c5a1b8ae40c1b7f24e293a012ad2add
49339926 | | motorway | 010200...CA96...0 | 04b4336b997e7ea9d99208bd487bbe7d
(6 rows)
我想要一个包含 3 行(每个 md5 哈希一个)和任何其他相应行的结果。因此,“ae945148417ada285130c59277c48a25”的有效行可能包含 osm_id-highway 对“-1641383”和“motorway”或“23133731”和“motorway_link”——我不介意并且认为两者都是正确的。
我该如何解决这个问题以及如何调用所需的操作/技术?所以我下次知道如何将其称为要搜索的内容。