ORACLE SQL - Complex Report

Asked

Viewed 70 times

0

Good morning, I need to take a report that is not made available by the system, working with the invoices table. In this table there is the customer data, consumer unit and the debit value. It turns out that a customer can have more than one consumer unit and, in each consumer unit, accurate the total 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 am facing problems with GROUP BY because, because of the sum function, I have to group the customer and consumer unit, and the generated report ends up coming out wrong. How can I solve?

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
  • put an example of the returned data, and an example of the data you need. (even serves what is already in the question, but the name of customers will repeat on the lower lines)

  • Since Oracle would think of "Analytic functions" https://blogs.oracle.com/oraclemagazine/a-window-into-the-world-of-analytic-functions

  • There would be no problem to repeat customer data, but it is returning customer data with only one consumer unit. I’ll take a look at the functions Analytic, thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.