写入这部分请求中不可能参考。 /Podzaprose./ 错误

我在我的请求中收到以下错误:


here is an entry for table "table1", but it cannot be referenced from this part of the query.


这是我的要求:


SELECT id 
FROM property_import_image_results table1
LEFT JOIN /
SELECT created_at
FROM property_import_image_results
WHERE external_url = table1.external_url
ORDER BY created_at DESC NULLS LAST
LIMIT 1
/ as table2 ON /pimr.created_at = table2.created_at/
WHERE table2.created_at is NULL
已邀请:

董宝中

赞同来自:

您需要侧面连接可以在连接子集中引用外部表。

您还指的是别名
pimr

在连接方面,在请求中的任何地方不可用。 所以你需要改变它
table1

在连接方面。

你还必须给桌子

内部的

请求假名以避免混淆:


SELECT id 
FROM property_import_image_results table1
LEFT JOIN <b><i>LATERAL</i></b> /
SELECT p2.created_at
FROM property_import_image_results p2
WHERE p2.external_url = table1.external_url
ORDER BY p2.created_at DESC NULLS LAST
LIMIT 1
/ as table2 ON /<b><i>table1</i></b>.created_at = table2.created_at/
WHERE table2.created_at is NULL


编辑

也可以使用窗口函数解决此类请求:


select id
from /
select id,
max/created_at/ over /partition by external_url/ as max_created
FROM property_import_image_results
/ t
where created_at <> max_created;




能够

比聚合和联盟更快,就像你一样。 但很难说。 侧面化合物也非常有效。 它有优势,您可以添加要导出的任何列,因为不需要分组。

要回复问题请先登录注册