title: Grouping date of births in 2 month periods
body: <p>I'm running a simple query that's returning the number of children turning 2 (birthday last month or next month). The following query returns a single row with count:</p>
  
  <pre><code>SELECT COUNT(*)
  FROM table AS t
  -- Child turning 2
  AND t.dob &lt;= DATE_SUB(NOW(), INTERVAL 23 MONTH)
  AND t.dob &gt;= DATE_SUB(NOW(), INTERVAL 25 MONTH)
  </code></pre>
  
  <p>I'd like to be able to build on this query and return multiple count rows, each for a 2 month period so that I can predict 2nd birthdays moving forward.</p>
  
  <p>I could do something like this:</p>
  
  <pre><code>SELECT COUNT(*)
  FROM table AS t
  -- Child turning 2
  AND t.dob &lt;= DATE_SUB(NOW(), INTERVAL 23 MONTH)
  AND t.dob &gt;= DATE_SUB(NOW(), INTERVAL 25 MONTH)
  
  UNION
  
  SELECT COUNT(*)
  FROM table AS t
  -- Child turning 2
  AND t.dob &lt;= DATE_SUB(NOW(), INTERVAL 21 MONTH)
  AND t.dob &gt;= DATE_SUB(NOW(), INTERVAL 23 MONTH)
  
  UNION...
  </code></pre>
  
  <p>But this is stupidly inefficient and very clumsy.</p>
  
  <p>As an output I'd like to see something like this:</p>
  
  <pre><code>count    |date range
  ---------------------------------
  327      |2012-03-01 - 2012-04-31
  ---------------------------------
  532      |2012-05-01 - 2012-06-31
  </code></pre>
  
  <p>I think I need to do something with GROUP BY but am unsure about how to go about this. </p>
  
  <p>Many thanks.</p>