title: How to SELECT last calender month (not the interval)?
body: <p>I have date time field called transaction_date, in a report i need to select last calendar month, how do i do this ? (this should work for a month like January too)</p>
  
  <p>I came up with following but this only works if the month is NOT january, </p>
  
  <pre><code>SELECT SUM(amount)  AS pay_month FROM `users_payment`  WHERE  MONTH(transaction_datetime)= MONTH(NOW()) AND YEAR(transaction_datetime)=YEAR(NOW())
  </code></pre>
  
  <p>there are lot of examples using INTERVAL functions but this only select the time interval not the calendar month as i wanted too..</p>
  
  <p>like </p>
  
  <pre><code>SELECT SUM(amount)  AS `year_month` FROM `users_payment`   WHERE  DATE_ADD(NOW(), INTERVAL -1 MONTH) &lt; transaction_datetime 
  </code></pre>
  
  <p>but this is not what i want, i want to select sales sum of the DECEMBER only last year (remember there are other years too in the table which i dont want i.e 1979, 1981...etc)</p>
  
  <p>same report next section, i need to select last 2 calender months, I dont know have any idea on how to do this too.  </p>