Reputation: 275
Im working with Opencart and am a little leary when it comes to this stuff. I have this mysql query that works fine but now I need another one that shows this information from the last 30 days. The two columns from the table are amount, date_added How do I add the 30 day check to this query? I know I need to include the date_added column to the query but not sure how.
public function getSum() {
$query = $this->db->query("SELECT SUM(amount) as amount_sum FROM " . DB_PREFIX . "donate");
return $query->row;
}
Upvotes: 1
Views: 902
Reputation: 817
This should work (depends on the used data type):
"SELECT SUM(amount) as amount_sum FROM " . DB_PREFIX . "donate WHERE date_added >= (CURDATE() - INTERVAL 1 MONTH)"
Upvotes: 2