title: Mysql query to find count(id) of each month-year
body: <p>I am working in a refactoring of my code. And I am trying to get the result of a python script in a single query.</p>
  
  <p>I tried to do this:</p>
  
  <pre><code>  select year(created), month(created), count(*) as total_id
    from repository_clinicaltrial
    group by id, year(created), month(created)
    order by id, year(created), month(created);
  </code></pre>
  
  <p>to get the count of ids of each MONTH-YEAR.</p>
  
  <p>Using python i am doing this way:</p>
  
  <pre><code>dic_months = {1: "jan",
           2: "fev",
           3: "mar",
           4: "abr",
           5: "mai",
           6: "jun",
           7: "jul",
           8: "ago",
           9: "set",
           10: "out",
           11: "nov",
           12: "dez"
          }
  
  def retorna_dic_report(yearI):
  
      yearN = yearI + 1
  
  
      query_report = 'select created from repository_clinicaltrial where created &gt;= "%s-01-01" and created &lt; "%s-01-01";' % (yearI,
                                                                                                                            yearN)
  
  
      db = MySQLdb.connect(host= host,
                    user= user,
                    passwd= pass,
                    db= db)
      cur = db.cursor()
  
  
      cur.execute(query_report)
  
      dic_result = {}
      for row in cur.fetchall():
              try:
                 dic_result[dic_months[row[0].month]] = dic_result[dic_months[row[0].month]] + 1
              except:
                 if row[0].month == 12:
                 dic_result[dic_months[row[0].month]] = 1
  
      return dic_result
  </code></pre>
  
  <p>I want to use a single query that return the count of ids of each months in a range of years.</p>
  
  <p>is it possible?</p>