title: get SUM of another row of GROUP BY'd rows
body: <p>I have this table:</p>
  
  <p><img src="https://i.imgur.com/uYQHO.png" alt="table"></p>
  
  <p>This selection is is duplicated many times for different var_lines (which pretty much work as one row of data, or respondent for a survey) and set_codes (different survey codes).</p>
  
  <p>With this query:</p>
  
  <pre><code>SELECT
      *, COUNT(*) AS total
  FROM
      `data`
  WHERE
      `var_name` = 'GND.NEWS.INT'
  AND(
      `set_code` = 'BAN11A-GND'
      OR `set_code` = 'BAN09A-GND'
      OR `set_code` = 'ALG11A-GND'
  )
  AND `country_id` = '5'
  GROUP BY
      `data_content`,
      `set_code`
  ORDER BY
      `set_code`,
      `data_content`
  </code></pre>
  
  <p>The query basically counts the number of answers for a specific question. Then groups them survey (set_code).</p>
  
  <p>What I need is for each of the grouped <code>data_content</code> answers for GND.NEWS.INT to also show the SUM of all the corresponding GND_WT with the same var_line.</p>
  
  <p>For example if I had this:</p>
  
  <pre><code>data_id    data_content    var_name    var_line
  1          2               GND.NEW.INT 1
  2          1.4             GND_WT      1
  3          2               GND.NEW.INT 2
  4          1.6             GND_WT      2
  5          3               GND.NEW.INT 3
  6          0.6             GND_WT      3
  </code></pre>
  
  <p>I would get something like this:</p>
  
  <pre><code>data_id    data_content    var_name      var_line   total   weight
  1          2               GND.NEW.INT   1          2       3
  5          3               GND.NEW.INT   3          1       0.6
  </code></pre>
  
  <p>Thanks for any help.</p>