[Solved] PHP + MySQL Interval query last 1 month with sum problem


You don’t have $row["mbsent"] in your SELECT clause of your query. Perhaps you meant:

$sql = "SELECT SUM(mbsent) AS summ, mbsent FROM data WHERE datum < DATE_ADD(NOW(), INTERVAL -1 MONTH) AND user="csib" GROUP BY mbsent";

But that doesn’t make any sense either… so not sure what you are going for here.

Also, I think you got your date logic backwards. You want everything in the last month:

 $sql = "SELECT SUM(mbsent) AS summ, mbsent FROM data WHERE datum >= DATE_ADD(NOW(), INTERVAL -1 MONTH) AND user="csib" GROUP BY mbsent";

solved PHP + MySQL Interval query last 1 month with sum problem