5
I am learning about SQL and I have a certain problem to do certain calculations.
I would like to subtract the values of selects
below. I have tried to do the SUM ( A - B - C)
, but without success.
My code:
(SELECT sum (dr.valortitulo)
from fin_docbase dbr
join fin_documento dr on (dr.coddocbase = dbr.cod)
where dbr.codpessoa = p.cod
and dr.codtpmovimento = 101
and dr.status = 'ABE') as totalreceber,
(SELECT sum (d.valortitulo)
from fin_docbase db
join fin_documento d on (d.coddocbase = db.cod)
where db.codpessoa = p.cod
and d.codtpmovimento = 100
and d.status = 'ABE') as totalpagar ,
(Select sum (dc.valortitulo)
from fin_docbase dbc
join fin_documento dc on (dc.coddocbase = dbc.cod)
where p.cod = dbc.codpessoa
and dc.codtpmovimento = 111
and dc.codtpcobranca in (18,16,14)
and dc.status in ('DEV','DVL')) as totalcheques