title: MySQL - Combining multiple selects from same table into one result table with a group by
body: <p>I have a table of meter readings which holds a meterNo, readingValue and readingDate.</p>
  
  <p>I want to show the total sum of readingValue per meterNo per year.</p>
  
  <p>For example:</p>
  
  <pre><code>SELECT meterNo, SUM(readingValue) '2009' FROM readings
  WHERE readingDate &gt;= '2009-01-01' AND readingDate &lt;= '2009-12-31'
  GROUP BY meterNo;
  </code></pre>
  
  <p>Will display the table:</p>
  
  <pre><code>   meterNo  2009
     --------------
       4       50
       5       5
       12      30
       13      63
       18      18
       26      484
       27      21
       28      510
       29      28
  </code></pre>
  
  <p>Which is what I want, it shows the total reading value for each meter in 2009. However, I need the result table to display a column for each year. So it would be something like this:</p>
  
  <pre><code>   meterNo  2009  2010  2011  2012
     --------------------------------
       1             20    35     50
       2                   45     35
       3                   50     60
       4       50    35    20     30
       5       5     10    10     15
       6                          30
  </code></pre>
  
  <p>And so on...</p>
  
  <p>I can reuse the where part of the query:</p>
  
  <pre><code>WHERE readingDate &gt;= '2009-01-01' AND readingDate &lt;= '2009-12-31'
  </code></pre>
  
  <p>And just change the date for each year, butt how do I display each WHERE result as its own column in the one result table?</p>