title: Select two variables from in a single MYSQL request
body: <p>I'm trying to extract two variables from the same MySQL request depending on the value of a variable. I can extract these variables in two separate queries, but I'm sure it must be possible to combine them to produce two /columns of data in a single statement, perhaps with an if statement?</p>
  <p>I have a JOIN statement in there which is sort of throwing me a bit.</p>
  <p>The first request:</p>
  <pre><code>SELECT variables.value as &quot;Mean Power&quot;
  FROM variables
  INNER JOIN stat_types ON variables.id=stat_types.id
  WHERE stat_types.name=&quot;Mean&quot;;
  </code></pre>
  <p>The second request:</p>
  <pre><code>SELECT variables.value as &quot;Maximum Power&quot;
  FROM variables
  INNER JOIN stat_types ON variables.id=stat_types.id
  WHERE stat_types.name=&quot;Max&quot;;
  </code></pre>
  <p>The only thing which has changed is that the stat_type name changes from Max to Mean, and I would like to change the output column name accordingly.</p>
  <p>There will always be the same number of results for these two requests.
  Any help you can offer would be great!</p>
  <p><strong>Edit:</strong>
  I should make it clear  that I am after two time series' , not individual maximum values. The closest I have now achieved is with the code suggested below, slightly edited as follows:</p>
  <pre><code>SELECT
      v.id,
      (CASE WHEN st.name = 'Mean' THEN v.value END) AS `Mean Power`,
      (CASE WHEN st.name = 'Max'  THEN v.value END) AS `Maximum Power`
  FROM variables v
  INNER JOIN stat_types st
      ON v.id = st.id
  WHERE
      st.name = IN ('Mean', 'Max')
  </code></pre>
  <p>Which gives:</p>
  <pre><code>|id|Mean Power| Maximum Power|
  |1 |NULL      |9010          |
  |1 |NULL      |8999          |
  |1 |NULL      |9011          |
  |2 |9053      |NULL          |
  |2 |9040      |NULL          |
  |2 |9045      |NULL          |
  </code></pre>
  <p>Great. However, I want this:</p>
  <pre><code>|Mean Power| Maximum Power|
  |9053      |9010          |
  |9040      |8999          |
  |9045      |9011          |
  </code></pre>
  <p>So I need to combine the power values and I don't need the id as an output. For each value I also have a timestep which could be used if necessary. There is a max and mean for every timestep (same number of values)
  Thanks!</p>