title: How to get the data per month in MySQL
body: <p>I'm trying to get the data per every month. </p>
  
  <p>I'm a newbie at <code>MySQL</code>.</p>
  
  <p>I just google and learn from the internet.</p>
  
  <p>So, My Query may be not suitable.</p>
  
  <p>If not suitable, please fix my query.</p>
  
  <p><strong>HERE IS MY QUERY</strong></p>
  
  <pre><code>SELECT
    SUM( cr_dt &gt; EXTRACT( YEAR_MONTH FROM CURDATE() ) 
           AND 
         cr_dt &lt; EXTRACT( YEAR_MONTH FROM CURDATE() + INTERVAL 1 MONTH )
       ) as thisMonth, 
    SUM( cr_dt &gt; EXTRACT( YEAR_MONTH FROM CURDATE() - INTERVAL 1 MONTH
           AND
         cr_dt &lt; EXTRACT( YAER_MONTH FROM CURDATE()
       ) as last1Month
  FROM MYTABLE
  </code></pre>
  
  <p>I just found the <code>EXTRACT()</code> and <code>INTERVAL</code>, but I don't know it may suitable. </p>
  
  <p>If you have a better way to solve, share please.</p>
  
  <p><strong>WHAT I EXPECT</strong></p>
  
  <pre><code>| thisMonth | last1Month | 
  +-----------+------------+
  |  123      |  1294      |
  </code></pre>
  
  <p><strong>WHAT I SEE NOW</strong></p>
  
  <pre><code>| thisMonth | last1Month | 
  +-----------+------------+
  |  0        |  0         |
  </code></pre>
  
  <p><strong>SAMPLE DATAS</strong></p>
  
  <pre><code>| idx |        cr_dt        |
  +-----+---------------------+
  | 1   | 2018-02-01 17:00:00 |
  | 2   | 2018-02-19 16:00:00 |
  | 3   | 2018-02-28 15:00:00 |
  | 4   | 2018-03-04 14:00:00 |
  | 5   | 2018-04-01 13:00:00 |
  | 6   | 2018-04-09 12:00:00 |
  | 7   | 2018-04-12 11:00:00 |
  | 8   | 2018-04-17 10:00:00 |
  </code></pre>