1
I have 2 tables that stores type of different sales, and I need to add everything to get the amount to generate the charge, however I am not able to mount the sql query, follows:
SELECT CL.NOME,CL.id_cadastro_cliente, sum (L.VALOR_LANCAMENTO) as valor_total
from (
(SELECT CL.NOME,CL.id_cadastro_cliente, sum (L.VALOR_LANCAMENTO) as valor_total
FROM CADASTRO_ATENDIMENTO AS C
INNER JOIN CADASTRO_ATENDIMENTO_ITEM AS L ON (C.id_cadastro_atendimento = L.id_cadastro_atendimento)
INNER JOIN CADASTRO_Cliente AS CL ON (CL.id_cadastro_cliente = C.id_cadastro_cliente)
Where C.TIPO_OPERACAO = 'A VISTA' AND L.FATURA_NUMERO = 0 AND L.FATURA_ANO = 0 AND L.FATURA_PAGA = 'FALSE' AND C.REMETENTE LIKE '%'
AND C.DATA_ATENDIMENTO BETWEEN '2014-01-01' and '2016-01-01'
group by CL.id_cadastro_cliente
HAVING SUM(L.VALOR_LANCAMENTO) > 100
ORDER BY CL.NOME)
union all
(SELECT CL.nOME, CL.id_cadastro_cliente, sum (contador_final - contador_inicial) as valor_total
FROM cadastro_maquina_franquia_atendimento AS M
INNER JOIN CADASTRO_Cliente AS CL ON (CL.id_cadastro_cliente = M.id_cliente)
WHERE CARTAO IS NULL AND ID_CLIENTE > 0
group by CL.id_cadastro_cliente)
) as CONSULTA
INNER JOIN CADASTRO_Cliente AS CL
group by CL.id_cadastro_cliente
I’m having the following error:
ERROR: syntax error in or next to "group" LINE 30: group by CL.id_customer registration
You could put the table structure and format sql as code, to facilitate the understanding of who wants to help solve your problem..
– Julio Henrique Bitencourt
I apologize, what would be a formatting to facilitate understanding? because so for me is understandable.....
– HimorriveL