ORA-00904:相关子查询上的列名无效

时间:2018-10-11 20:18:27

标签: sql oracle query-performance ora-00904 oracle8i

我在关联Oracle 8i上的子查询时遇到问题

该子查询给我一个ORA-00904:无效的列名,我不明白为什么。不行吗?

SELECT
    HIST_FA.HIFA_PLAN_CODIGO                                                AS FE_CODIGO_PLANTEL,
    HIST_FA.HIFA_NUMERO                                                     AS FE_NUMERO_CONTROL,
    HIST_FA.HIFA_FECHA                                                      AS FE_FECHA_HORA_EMISION,
    HIST_FA.HIFA_DEST_CLIE_CODIGO                                           AS FE_CODIGO_CLIENTE,
    --  . . . a bunch of other columns . . .
FROM
    VFA_HIST_FA HIST_FA,
    VFA_HIST_ITEMS_FA HIST_ITEMS_FA,
    (
        SELECT
            HIRF_HIIF_HIFA_NUMERO                                           AS FE_NUMERO_CONTROL,
            SUM(DECODE(HIRF_RETE_CODIGO, 0, HIRF_MONTO))                    AS FE_MONTO_ENTREGADO,
            SUM(DECODE(HIRF_RETE_CODIGO, 5, HIRF_MONTO))                    AS FE_IMPUESTO_UNICO,
            SUM(DECODE(HIRF_RETE_CODIGO, 6, HIRF_MONTO))                    AS FE_MARGEN_COMERCIALIZACION
        FROM
            VFA_HIST_ITEMS_RETENC_FA
        WHERE
            HIRF_HIIF_HIFA_NUMERO = HIST_FA.HIFA_NUMERO
        GROUP BY
            HIRF_HIIF_HIFA_NUMERO
    ) PP  
WHERE
    HIST_FA.HIFA_NUMERO = HIST_ITEMS_FA.HIIF_HIFA_NUMERO;

当然,我可以在主WHERE上执行此操作,但是它将扫描内部行中的所有行。

HIST_FA.HIFA_NUMERO = PP.FE_NUMERO_CONTROL

因此,这不是一种选择,因为查询将变得持​​久。

最诚挚的问候!

1 个答案:

答案 0 :(得分:1)

更改列名的别名 HIRF_HIIF_HIFA_NUMERO AS FE_NUMERO_CONTROL 改成其他名称,然后重试。