Can someone help me ?

I have 3 tables:

  • Table document – columns: idDocument, time,etc…
  • Table details – columns: idDocument (relation), idCatalogue, price, etc…
  • Table catalogue – columns: IdCatalogue, weight, name, etc…

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…