date - Looking for a mysql query to count all rows previous to last month -


i'll skip "why" brevity. if want know can ask. first quest find way count rows previous current month. found solution works, is:

select count(*) mytable  log_date < (curdate() -  dayofmonth(curdate())) 

i subtract number of days has transpired month , count rows date less first day of month.

the next problem need count rows before last month. guess technically take result above , query results of last month , subtract 2 queries. hoping single query this. have tried variations of 2 versions below:

select count(*) mytable  log_date < ((curdate()- dayofmonth(curdate())) - interval 1 month) 

and

select count(*) mytable  log_date < date_sub((curdate()- dayofmonth(curdate())), interval 1 month) 

both of these approaches along variations of have tried yield result of 0 when know answer should 14.

is there way answer looking in single query?

thanks.

try this:

select count(*) `mytable` `log_date` between "2010-11-01 00:00:00" , "2010-11-30 23:59:59" 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -