title: Mysql query to sum rows and columns based on column criteria
body: <p>Please help me with writing a query for the following condition. I have a table which I have listed below</p>
  
  <pre><code>ID  Wt1  Wt1_Type  Wt2  Wt2_Type  Wt3   Wt3_Type  Wt4  Wt4_Type
  --------------------------------------------------------------
  1   200  1         220  1         300   2         400  3    
  2   100  4         150  3         100   5         120  1  
  3   100  3         110  1         200   5         100  4
  </code></pre>
  
  <p>I want a query to sum all the the weights (wt1, wt2, wt3, wt4) grouped on the weight type (wt1_type, wt2_type, wt3_type, wt4_type).</p>
  
  <p>The output should look like</p>
  
  <pre><code>Wt_type   Total
  1         650
  2         300
  3         650
  4         200
  5         300
  </code></pre>
  
  <p>Can someone please help me draft a mysql query to get this result ?</p>
  
  <p>Thanks</p>