1 2 3 4 5 6 7 8 9 10 11 12
|
select
sum(ca) as ca , sum(gainproduit) "gain produit", sum(depenses) as "depenses total", sum(canalsat) as "total canalsat", month(dated) as mois , year(dated) as annee
from
(
select v.dateVente as dated , v.idBtq as idBtq ,v.qteVendu*(v.prixVente - v.prixAchat) as gainproduit ,0 as canalsat, 0 as depenses , (v.qteVendu * v.prixVente) as ca from ventes v
union all
select d.dateDep as dated, d.idBtq as idBtq , 0 as gainproduit ,0 as canalsat, d.montant as depenses , 0 as ca from depenses d
union all
select c.dateCanal as dated ,c.idBtq as idBtq , 0 as gainproduit , c.gain as canalsat, 0 as depenses , 0 as ca from canal c
) x
group by year(dated) , month(dated) |
Partager