【发布时间】:2021-03-23 07:26:20
【问题描述】:
当我运行此查询时,卡在“等待查询完成”
with
cte1 as (
select
id as c,
ST_SetSRID(ST_MakePoint(lo, la), 4326) as u_t1
from t1
),
cte2 as (
select
t2.a1 as c,
st_union(t2.way) as c1
from t2
group by c
),
cte3 as(
select sum (t3.a2) as sum1
from cte1, cte2, t3
where st_intersects(cte1.u_t1, cte2.c1)
group by cte2.c1
)
select
cte3.sum1
cte2.c
from cte3, cte2
查询的建议是SUM 一个带有ST_INTERSECTS 限制的INT 列。 st_intersect 的属性在 ct1 和 ct2 中推导出来。我想这可能需要一些时间,但问题是查询永远不会完成。
知道为什么吗?
谢谢!
【问题讨论】:
-
不使用 ANSI 连接语法,您正在创建潜在的巨大笛卡尔积。请在这里花几分钟:w3schools.com/sql
-
感谢您的回复。我正在自学,虽然有时我需要帮助,但感谢您提供的链接。
标签: postgresql postgis common-table-expression spatial