如何在Ruby Sequel中编写此SQL查询:
SELECT
polygon.geometry, count(line)
FROM
polygon, line
WHERE
st_intersects(line.geometry, polygon.geometry)
GROUP BY
polygon.geometry
答案 0 :(得分:0)
可能有更好的方法,但这是我的解决方案:
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\"">
答案 1 :(得分:0)
DB[:polygon, :line].
select_group(:polygon__geometry).
select_append{count(line)}.
where{st_intersects(:line__geometry, :polygon__geometry)}