1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
SELECT AR.arcticle, AR.quantiteInv, AES.sumEntree, ASS.sumSortie,
AR.quantiteInv + AES.sumEntree - ASS.sumSortie as stockArticles
FROM ( Articles as AR
LEFT JOIN ( SELECT AE.articles, SUM(AE.entreeQuant) as sumEntree
FROM ArticlesEntr as AE
WHERE AR.dateInv < AE.entreeDate
GROUP BY AE.articles
) as AES
ON (AR.articles = AE.articles)
)
LEFT JOIN ( SELECT AS.articles, SUM(AS.sortieQuant) as sumSortie
FROM ArticlesSort as AS
WHERE AR.dateInv < AS.sortieDate
GROUP BY AS.articles
) as ASS
ON (AR.articles = AS.articles)
) |
Partager