【发布时间】:2020-03-17 09:17:03
【问题描述】:
我想在 from 和 where 子句中使用相同的子查询。 尝试了以下两种方法,但在两种情况下在查询的不同位置都出现了相同的错误。
问题 1:
select * from (subquery1) as t_feature where id = (select MAX(id) from t_feature);
问题 2:
select * from t_feature where id = (select MAX(id) from (subquery1) as t_feature);
错误:
ERROR: relation "t_feature" does not exist
对于临时灵魂,我为子查询创建了一个视图,并用它来代替子查询。但我不想为这种情况创建视图。
【问题讨论】:
-
也许你应该看看 rank() 函数。我在这里发布了示例:stackoverflow.com/questions/16892902/…
标签: postgresql subquery correlated-subquery