Bom dia. Poderia me explicar o porque de quando eu adiciono uma JOIN, é adicionado um caractere 0 no final de uma soma de valores (campo fat_total_2017)?
Query 1 - OK
cod_cliente, cliente, representante, fam_comercial, qtde_faturada, fat_total_2017
'1652', 'RANDON S/A IMPL PARTICIPACOES', 'MARCELO MARZOTTO', '301', '6762', 'R$ 514.136,00'
SELECT
     tc.`cod-emitente` AS cod_cliente,
     tc.`nome-emit` AS cliente,
     tr.`nome` AS representante,
     fg.`fm-cod-com` AS fam_comercial,
     sum(fg.`qt-faturada`) AS qtde_faturada,
     CONCAT('R$ ', REPLACE(REPLACE(REPLACE(format(sum(fg.`vl-merc-liq`), 2),'.',';'),',','.'),';',',')) AS fat_total_2017
FROM tb_clientes tc 
INNER JOIN tb_representantes tr ON tr.`cod-rep` = tc.`cod-rep` 
INNER JOIN faturamento_global fg ON fg.`cod-emitente` = tc.`cod-emitente` 
WHERE tc.`cod-emitente` > '4'
AND fg.`data-estat` >= '2017-01-01'
AND fg.`fm-cod-com` = 301
AND fg.`ind-devolucao` = 0
AND tc.`cod-emitente` = 1652
GROUP BY fg.`fm-cod-com`, tc.`cod-emitente`Query 2 - NOK
cod_cliente, cliente, representante, qtde_visita, fam_comercial, qtde_faturada, fat_total_2017
'1652', 'RANDON S/A IMPL PARTICIPACOES', 'MARCELO MARZOTTO', '10', '301', '67620', 'R$ 5.141.360,00'
SELECT
     tc.`cod-emitente` AS cod_cliente,
     tc.`nome-emit` AS cliente,
     tr.`nome` AS representante,
     count(distinct(av.`CodVisita`)) AS qtde_visita,
     fg.`fm-cod-com` AS fam_comercial,
     sum(fg.`qt-faturada`) AS qtde_faturada,
     CONCAT('R$ ', REPLACE(REPLACE(REPLACE(format(sum(fg.`vl-merc-liq`), 2),'.',';'),',','.'),';',',')) AS fat_total_2017
FROM tb_clientes tc 
INNER JOIN tb_representantes tr ON tr.`cod-rep` = tc.`cod-rep` 
INNER JOIN faturamento_global fg ON fg.`cod-emitente` = tc.`cod-emitente` 
INNER JOIN agnd_visitas av ON av.`idDestino` = tc.`cod-emitente`
WHERE tc.`cod-emitente` > '4'
AND av.`dtVisita2` >= '2017-01-01'
AND fg.`data-estat` >= '2017-01-01'
AND fg.`fm-cod-com` = 301
AND fg.`ind-devolucao` = 0
AND tc.`cod-emitente` = 1652
GROUP BY fg.`fm-cod-com`, tc.`cod-emitente`Obrigado.
 
            