如何获取交易记录的最后日期到当前日期的月份间隔?

How can I get the month interval of a transaction from the last date of it's record to the current date?

如何获取交易记录的最后日期到当前日期的月份间隔? 让我们看看下面的table!

---------------------------------------
|transaction_dates | transaction_time |
---------------------------------------
|2015-01-02        | 11:00:00         |
|2015-01-03        | 12:00:00         |
|2015-02-05        | 7:00:00          |
|2015-03-05        | 10:00:00         |
|2015-03-05        | 19:00:00         |
|2015-04-05        | 13:00:00         |
---------------------------------------

从当前日期(2015 年 8 月 20 日)开始。我在 5 月、6 月和 7 月没有任何交易。因此,通过执行一些 PHP 脚本和 SQL,我怎样才能得到交易闲置到当前日期的月份?在上面的例子中,我想要的输出是

-------------
|months_idle|
-------------
|5           |
|6           |
|7           |
--------------

在您的数据库中创建 table 月份 (1..12) 和 select 整个月份 > max(MONTH(transaction_dates)) 和 < MONTH(NOW())