title: MySQL query to get count of current month and last month to get percentage of growth
body: <p>What im trying to achieve is to get the current count and last month count so i can do a formula to get the growth percentage</p>
  
  <pre><code>(CountCurrent - CountLastMonth) / CountLastMonth 
  </code></pre>
  
  <p>My table has the following fields</p>
  
  <pre><code>activity, upload_date
  </code></pre>
  
  <p>This is the query im trying now.</p>
  
  <pre><code>SELECT  
          Y.CurrentMonth,     Y.CountCurrent,
          Z.LastMonth,  Z.CountLastMonth
  
  
   FROM 
          (SELECT
          upload_date,
          activity,
              DATE_FORMAT(upload_date,'%M %Y') AS CurrentMonth, 
          COUNT(activity) AS CountCurrent
              FROM appmaster
              WHERE activity = 'com.google.test'
              GROUP BY DATE_FORMAT(upload_date,'%m%y')) 
      Y INNER JOIN 
          (SELECT 
          activity,
          DATE_FORMAT(upload_date,'%M %Y') AS CurrentMonth2, 
              DATE_FORMAT(upload_date - INTERVAL 1 MONTH,'%M %Y') AS LastMonth, 
              COUNT(activity) AS CountLastMonth
          FROM appmaster
          WHERE activity = 'com.google.test'
          GROUP BY DATE_FORMAT(upload_date - INTERVAL 1 MONTH,'%m%y'))
      Z ON Z.CurrentMonth2 = Y.CurrentMonth 
  
  GROUP BY DATE_FORMAT(upload_date,'%Y%m')
  ORDER BY DATE_FORMAT(upload_date,'%Y%m')
  </code></pre>
  
  <p>My CurrentMonth, CountCurrent and LastMonth work fine. But the CountLastMonth is coming out the same as CountCurrent.</p>
  
  <p>I was trying this before and it would give me everything but the CountLastMonth</p>
  
  <pre><code>SELECT b.CurrentMonth, sum(b.CountCurrent), b.LastMonth
  FROM (SELECT DATE(a.upload_date - INTERVAL 1 MONTH) AS LastMonth, DATE(a.upload_date) AS CurrentMonth, COUNT(a.activity) AS CountCurrent 
  FROM appmaster a WHERE a.activity = 'com.google.android.googlequicksearchbox'
  group BY MONTH(a.upload_date)) AS b
  
  group BY MONTH(b.CurrentMonth)
  </code></pre>