Stack Exchange
Is there a solution for finding SQL Query with join of 3 tables and do some opperations in a period?
Is there a way of finding SQL Query with join of 3 tables and do some operations in a period?
Query below:
https://i.stack.imgur.com/SpWkt.png
 
SELECT ST.code,ST.Plant,ST.STINT,E.code,E.Plant,SUM(E.Quantite) AS E_Qte,S.code,S.Plant,S.S_Qte 
    FROM `enter` E 
    INNER JOIN (SELECT code,Plant,SUM(Quantite) AS S_Qte FROM `sortie` group by code,Plant) S 
    INNER JOIN 
    (SELECT code,plant,sum(stockinitiale) AS STINT 
    FROM `stockinitiale` group by code,Plant) ST ON E.Code= S.Code=ST.Code AND E.Plant= S.Plant=ST.Plant 
    WHERE date BETWEEN '2019-05-17' AND '2019-05-28' 
    GROUP BY E.code,S.code,ST.code,E.Plant,S.Plant,ST.Plant

Expected output:
+------+-------+-------+------+-------+-------+------+-------+--------+
| code | Plant | STINT | code | Plant | E_Qte | code | Plant | S_Qte  |
+------+-------+-------+------+-------+-------+------+-------+--------+
| 1001 | P1    |   122 | 1001 | P1    |   662 | 1001 | P1    |     19 |
| 1001 | P3    |   108 | 1001 | P3    |    10 | 1001 | P3    |      2 |
| 1002 | P1    |     0 | 1002 | P1    |     4 | 1002 | P1    |     15 |
| 1002 | P3    |     6 | 1002 | P3    |     7 | 1002 | P3    |     12 |
| 1008 | P1    |    12 | 1001 | P1    |    66 | 1001 | P1    |     17 |
+------+-------+-------+------+-------+-------+------+-------+--------+


is this a typo 'on E.Plant= S.Plant=ST.Plant '? AND you need an on clause for your first join

First thank u for ur comment. This query work but when i add E.code= S.code=ST.code i got  empty display!

I didn't check anything else, just for the case of your join you may try this...
    SELECT ST.code,ST.Plant,ST.STINT,E.code,E.Plant,sum(E.Quantite) AS E_Qte,S.code,S.Plant,S.S_Qte
    FROM enter E 
    INNER JOIN 
    (SELECT code,Plant,sum(Quantite) As S_Qte FROM sortie group by code,Plant) S ON E.Plant= S.Plant
    INNER JOIN 
    (SELECT code,plant,sum(stockinitiale) AS STINT FROM stockinitiale group by code,Plant) ST on S.Plant=ST.Plant 
    where date between '2019-05-17' and '2019-05-28' group by E.code,S.code,ST.code,E.Plant,S.Plant,ST.Plant

Although it is better if you post your input and expected output, if this is not working for your case.

Please check my expected output
