miércoles, 3 de junio de 2020

SQL Query to find difference in the trial balance

SELECT
    fa.ad_table_id,
    fa.record_id,
    SUM (
    COALESCE ( fa.amtsourcedr, 0 )) AS debito_fuente,
    SUM (
    COALESCE ( fa.amtsourcecr, 0 )) AS credito_fuente,
    (
    SUM (
    COALESCE ( fa.amtsourcedr, 0 )) - SUM (
    COALESCE ( fa.amtsourcecr, 0 ))
    ) AS dif_fuente,
    SUM (
    COALESCE ( fa.amtacctdr, 0 )) AS debito_conta,
    SUM (
    COALESCE ( fa.amtacctcr, 0 )) AS credito_conta,
    (
    SUM (
    COALESCE ( fa.amtacctdr, 0 )) - SUM (
    COALESCE ( fa.amtacctcr, 0 ))
    ) AS dif_conta
FROM
    adempiere.fact_acct AS fa
WHERE
    fa.ad_client_id = 1000000
    AND fa.gl_distrib_account = 1
    AND fa.c_period_id = 1000056
GROUP BY
    1,
    2
HAVING
    (
    SUM (
    COALESCE ( fa.amtacctdr, 0 )) - SUM (
    COALESCE ( fa.amtacctcr, 0 ))
    ) != 0

No hay comentarios:

Publicar un comentario