title: Mysql query rows to columns but columns separed by meta_key
body: <p>i've got an itemmeta table like this: </p>
  
  <pre><code>item_id meta_key     meta_value
        1 variation_id        123
        1 qty                   3
        2 variation_id        100
        2 qty                   2
        3 variation_id        123
        3 qty                   4
  </code></pre>
  
  <p>What i need:</p>
  
  <pre><code>123 7
  100 2
  </code></pre>
  
  <p>I can do what i want with a subquery like: </p>
  
  <pre>
  SELECT DISTINCT m1.meta_value AS variation_id,
       ( SELECT SUM(m2.meta_value) 
         FROM itemmeta m2 
         WHERE m2.meta_key='qty' AND m1.item_id = m2.item_id ) AS qty 
  FROM itemmeta m1
  WHERE m1.meta_key = 'variation_id'
  </pre>
  
  <p>But i wondering are there any better, simpler or more efficient solution?</p>
  
  <p>Thank you!</p>