如何用Ruby Sequel编写这个SQL查询:
SELECT
polygon.geometry, count(line)
FROM
polygon, line
WHERE
st_intersects(line.geometry, polygon.geometry)
GROUP BY
polygon.geometry
最佳答案
也许有更好的方法,但这是我的一个解决方案:
DB.from(:polygon, :line)
.where('st_intersects(line.geometry, polygon.geometry')
.select('polygon.geometry, count(line)')
.group_by(:polygon__geometry)
生成的SQL查询(我使用Oracle DB执行了此操作,但结果应该相同):
#<Sequel::Oracle::Dataset: "SELECT 'polygon.geometry, count(line)' FROM \"POLYGON\", \"LINE\" WHERE (st_intersects(line.geometry, polygon.geometry) GROUP BY \"POLYGON\".\"GEOMETRY\"">
关于ruby - Ruby Seque中的空间where子句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37864337/