views:

25

answers:

3

Hello,

few times ago, i asked how to do to display datas 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

  • 10 june to the 10 may
  • then the 10 may until the 10 april...

But what i want is data :

  • from 1st may to 1 st june,
  • from 1st june to 1st july...

do you see what i mean ?

thank you ;)

+2  A: 

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.

halfdan
Close, but no Pepsi ;)
barrycarter
yours doesn't work, i'm sorry :D
Tristan
+1  A: 

AND MONTH(v.date)=6 AND YEAR(v.date)=2009 [to get everything in June 2009]

barrycarter
Ok it's working fine ;)thanks ;)
Tristan
A: 

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

schemathings