You are on page 1of 1

SELECT inc.fecha,inc.concepto,inc.cantidad,outc.cantidad , (inc.cantidad-outc.

ca
ntidad) FROM outc,inc
where inc.concepto=outc.concepto AND inc.fecha=outc.fecha
UNION
SELECT inc.fecha,inc.concepto,inc.cantidad,0,inc.cantidad
FROM inc where not exists(select * from outc where outc.fecha=inc.fecha AND outc
.concepto=inc.concepto)
UNION
SELECT outc.fecha,outc.concepto,outc.cantidad,0,0-outc.cantidad
FROM outc where not exists(select * from inc where inc.fecha=outc.fecha AND outc
.concepto=inc.concepto)
;
ultimo
-------
select inc.concepto,sum(inc.cantidad),sum(outc.cantidad),sum(inc.cantidad)-sum(o
utc.cantidad)
from inc,outc
where inc.concepto=outc.concepto group by 1
UNION
select inc.concepto,sum(inc.cantidad),0,sum(inc.cantidad)
from inc
where not exists (select * from outc where outc.concepto=inc.concepto)group by 1

UNION
select outc.concepto,0,sum(outc.cantidad),0-sum(outc.cantidad)
from outc where not exists(select * from inc where inc.concepto=outc.concepto) g
roup by 1

You might also like