I'm learning about SQL and I'm having a problem making certain calculations.
I would like to subtract values from selects
below. I've already tried to SUM ( A - B - C)
, but to no avail.
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