ORACLE SQL - Complex report

0

Good morning, I need to get a report that is not made available by the system, working with the invoices table. In this table there is the data of the customer, consumer unit and the value of the flow. It turns out that a customer can have more than one consumer unit, and in each consumer unit, he needs the total of the debt. Example:

cliente a | Unidade consumidora 1 | Total de débitos

          | Unidade consumidora 2 | Total de débitos

cliente b | Unidade consumidora 3 | Total de débitos

cliente c | Unidade consumidora 4 | Total de débitos

          | Unidade consumidora 5 | Total de débitos

          | Unidade consumidora 6 | Total de débitos

I'm having problems with GROUP BY because, because of the sum function, I have to group the client and consumer unit, and the generated report ends up going wrong. How can I fix it?

I tried to use:

SELECT cliente, unidade_consumidora, sum(valor_fatura) "Total de débitos"

from cad_fatura

GROUP BY cliente, unidade_consumidora

ORDER BY cliente, unidade consumidora
    
asked by anonymous 13.06.2018 / 14:42

0 answers