Postgresql - 避免子查询的别名

时间:2014-11-04 06:41:35

标签: postgresql subquery

是否可能有Postgresql的插件或选项允许省略子查询的别名?

例如,我必须写一个这样的查询:

select * from filelist2 
where md5sum in(
select md5sum from(
select md5sum, count(md5sum) from filelist2 
group by md5sum
having count(md5sum)>1) as MANDATORY_ALIAS)
order by md5sum;

如果没有别名,我会收到以下错误:

ERROR: subquery in FROM must have an alias
SQL Status:42601

我发现这非常烦人,想要省略它,就像大多数其他数据库一样。

1 个答案:

答案 0 :(得分:0)

如果要在此查询中使用别名,请删除子选择:

SELECT * 
FROM  filelist2 
WHERE md5sum IN(
    SELECT md5sum
    FROM filelist2 
    GROUP BY md5sum
    HAVING COUNT(md5sum) > 1
    )
ORDER BY 
    md5sum ASC;