我对新创建的别名 ABONO 和 CARGO 有疑问。ALIASES(用于结果的列名)和 SQL 查询工作正常,直到我尝试计算“ABONO-CARGO AS AJUSTE”=> Interbase 给出它不知道“ABONO”列的错误。
动态 SQL 错误 SQL 错误代码 = -206 列未知 ABONO
怎么了?
SELECT M."MOV_CUENTA",
(SELECT SUM(MM."MOV_MONTO")
FROM "movimientos" MM
WHERE MM."MOV_TIPOMOV" = 'A' AND MM."MOV_CUENTA" = CS."ID_CUENTAMUN"
GROUP BY MM."MOV_CUENTA"
) AS ABONO,
(SELECT SUM(XM."MOV_MONTO")
FROM "movimientos" XM
WHERE XM."MOV_TIPOMOV" = 'C' AND XM."MOV_CUENTA" = CS."ID_CUENTAMUN"
GROUP BY XM."MOV_CUENTA"
) AS CARGO,
ABONO-CARGO AS AJUSTE
FROM "cuentasSaldo" CS
INNER JOIN "movimientos" M ON (CS."ID_CUENTAMUN" = M."MOV_CUENTA")
INNER JOIN "ajustes" AA ON (M."ID_AJUSTE" = AA."ID_AJUSTE")
INNER JOIN "documentos" DD ON (AA."ID_DOCUMENTO" = DD."ID_DOCUMENTO")
WHERE M."ID_AJUSTE" IN
(SELECT A."ID_AJUSTE"
FROM "ajustes" A
WHERE A."ID_DOCUMENTO" IN
(SELECT D."ID_DOCUMENTO"
FROM "documentos" D
WHERE D."ID_EMPRESA" = 1 AND D."DOC_EDITABLE" = 1
)
)
ORDER BY M."ID_AJUSTE", M."MOV_CUENTA"