我对SQL还不太熟悉,我尝试做一个特定的查询,其中需要两个子查询。我必须给他们取别名,但当我这么做的时候会说:

ERROR:  syntax error at or near "as"

但我看语法上没有什么问题。我在这类查询中遇到了很多问题,而且找不到太多信息或示例。你能帮我吗?
Select
    ...
from
    turno,
    (select * from
        (
            select
                ...
             from
                accion
            where
                accion.tipo = 4 or accion.tipo = 5
        ) as part1
        union
        (
            select
                ...
             from
                accion
            where
                accion.tipo <> 4 and accion.tipo <> 5
        ) as part2
    ) as accion
where
    ...
;

谢谢。

最佳答案

尝试:

Select
    ...
from
    turno,
    (select * from
        (
            select
                ...
             from
                accion
            where
                accion.tipo = 4 or accion.tipo = 5
         union
            select
                ...
             from
                accion
            where
                accion.tipo <> 4 and accion.tipo <> 5
        ) as part1_2
    ) as accion
where
    ...
;

关于sql - PostgreSQL子查询中带有别名的语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8435358/

10-12 03:34