Site icon Facta Media

SQL SUM in table with 3 relationships [closed]

Can someone help me ?

I have 3 tables:

How can I have the sum of weight from all documents who are paid between 2 dates ?

This is what I tried:

SELECT 
    SUM(weight) AS totalMois 
FROM 
    catalogue 
WHERE 
    idCatalogue IN (SELECT idCatalogue FROM details 
                    WHERE idDocument IN (SELECT IdDocument 
                                         FROM documents 
                                         WHERE MONTH(FROM_UNIXTIME(time_transaction)) = ? 
                      AND YEAR(FROM_UNIXTIME(time_transaction)) = ? 
                      AND etat = 2))

Thanks.

The result is for a JPgraph by month in a year…

Exit mobile version