Reputation: 8855
Few times ago, I asked how to do to display data per month, I must told a bad explanation because I just figured out that it's not what I want :
Here's what I got :
$req1 = ...
AND v.date > (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))
AND v.date < (DATE_SUB(CURDATE(), INTERVAL 1 MONTH))
$req2= ...
AND v.date > (DATE_SUB(CURDATE(), INTERVAL 3 MONTH))
AND v.date < (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))
But the problem, imagine that today you are the 10th June, it's going to calculate ALL the data between the
But what I want is data :
Do you see what I mean ?
Upvotes: 0
Views: 130
Reputation: 47
select month(v.date), year(v.date), sum(somedatacolumn) from thetable group by month(v.date), year(v.date);
replace sum with whatever calculation you are doing
Upvotes: 0
Reputation:
AND MONTH(v.date)=6 AND YEAR(v.date)=2009 [to get everything in June 2009]
Upvotes: 2
Reputation: 34214
You could use:
WHERE YEAR(date) = 2010 AND MONTH(date) = 5
to get all rows where date is in the YEAR 2010 and the fifth month of the year.
Upvotes: 3