Sum result of 2 fields

Asked

Viewed 62 times

1

I could use a little help with a consult. I have a sales chart where has the field vltotal and vldevolucao, the total of these fields already managed, but I’m not getting the result of the sum of them. My script is:

select distinct codusur, sum(vltotal) as valor, sum(vldevolucao) as 
Devolucao, count(codcli), sum(vltotal - vldevolucao) as liquido

from pcnfsaid
where dtsaida between trunc(sysdate, 'month') and sysdate

and vlbonific = 0

and codsupervisor = 2

group by codusur

order by codusur

I have that result:

inserir a descrição da imagem aqui

  • I don’t know if I understand, but try "rollup" or "Cube" https://oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets

  • I need the LIQUID to be VALUE - DEVOLUCAO. See in this example: codusur 4 - 13990,36 - 419,19 the correct would be LIQUIDO 13574,17 codusu 7 - 18832,30 - 953,80 the correct would be LIQUIDO 17878,50

  • Try taking out the "distinct"

1 answer

0


Try it this way:

select distinct codusur, sum(vltotal) as valor, sum(vldevolucao) as 
Devolucao, count(codcli), sum(vltotal) - sum(vldevolucao) as liquido
from pcnfsaid
where dtsaida between trunc(sysdate, 'month') and sysdate
and vlbonific = 0
and codsupervisor = 2
group by codusur
order by codusur
  • 1

    Blz! worked right! Thank you

Browser other questions tagged

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