我希望在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
对于临时解决方案,我已经为子查询创建了一个视图,并使用该视图代替了子查询。但我不想为这个案例创建视图。
发布于 2020-03-17 09:28:02
使用公共表表达式
with t_feature as (
...
)
select *
from t_feature
where id = (select MAX(id) from t_feature);
https://stackoverflow.com/questions/60719364
复制相似问题