title: Mysql - Improving consultation query in 'group by'
body: <p>I have a query with 'group by':</p>
  
  <pre><code>
  SELECT date_audience, 
      Sum( If( quality_apuration = '1', 1, 0 ) ) AS very_good, 
      Sum( If( quality_apuration = '2', 1, 0 ) ) AS good, 
      Sum( If( quality_apuration = '3', 1, 0 ) ) AS bad, 
      Sum( If( quality_apuration = '4', 1, 0 ) ) AS no_apuration, 
      Count(quality_apuration) AS total 
  
      FROM pp_base 
  
      WHERE date_audience >= '2011-01-01' AND date_audience &lt;= '2011-02-28'
  
      GROUP BY date_audience ORDER BY date_audience ASC
  
  </code></pre>
  
  <p>Where to return the following result (or see <a href="http://jsbin.com/imuru5/" rel="nofollow noreferrer">http://jsbin.com/imuru5/</a>):</p>
  
  <p><img src="https://i.stack.imgur.com/v3CoY.jpg" alt="Table Results"></p>
  
  <p>As the table X has foreign key to another table Y, eventually someone will ask to include one more item in the table Y, for example: 'exccelent', 'regular', etc. And I will also have to adjust the schedule as php  $query[0]['very_good'], $query[0]['good'],  $query[0]['bad'], etc, adding among other items, spending more time .</p>
  
  <p>Does anyone have any idea how I can improve this query, in order to automate the results?</p>
  
  <p>Thanks, Vinicius.</p>