title: PHP + MYSQL SUM between same field value
body: <p>I'm working on work order progress system.</p>
  
  <p>I have this query:</p>
  
  <pre><code>SELECT c.sheet_no
       , c.step
       , a.crew_est
       , a.manhour_est
       , c.act_hours
    FROM work_sheet_machine a 
    LEFT 
    JOIN machine_master_data b 
      ON a.machine_code = b.code
    JOIN daily_activity_control_card-man c 
      ON c.wo_number = a.wo_number
     AND c.sheet_no = a.sheet
     AND c.step = a.serial
    LEFT 
    JOIN machine_master_data d 
      ON c.machine_code = d.code
   WHERE a.wo_number = 'I7474549';
  </code></pre>
  
  <p>MYSQL return me this result:</p>
  
  <pre><code>+----------+------+----------+-------------+-----------+
  | sheet_no | step | crew_est | manhour_est | act_hours |
  +----------+------+----------+-------------+-----------+
  |        1 |    1 |        1 |         0.5 |        35 |
  |        1 |    2 |        2 |           2 |        11 |
  |        1 |    2 |        2 |           2 |        11 |
  |        1 |    3 |        2 |           3 |        11 |
  +----------+------+----------+-------------+-----------+
  4 rows in set (0.00 sec)
  </code></pre>
  
  <p>The result is good, but I need to get <strong>total_act_hours</strong> for each same step number, so the result I need to get is look like this (please click run code snippet to see the result):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table border="1"&gt;
  &lt;tr&gt;
  &lt;td&gt; sheet_no &lt;/td&gt;
  &lt;td&gt; step &lt;/td&gt;
  &lt;td&gt; crew_est &lt;/td&gt;
  &lt;td&gt; manhour_est &lt;/td&gt;
  &lt;td&gt; act_hours &lt;/td&gt;
  &lt;td&gt; total_act_hours &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 0.5 &lt;/td&gt;
  &lt;td&gt; 35 &lt;/td&gt;
  &lt;td&gt; 35 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 11 &lt;/td&gt;
  &lt;td rowspan="2"&gt; 11 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 11 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt; 1 &lt;/td&gt;
  &lt;td&gt; 3 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 2 &lt;/td&gt;
  &lt;td&gt; 3 &lt;/td&gt;
  &lt;td&gt; 11 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>How can I achieve this in MYSQL query or MYSQL + PHP code?</p>
  
  <p>Anyhelp will be much appreciated.
  Thank you.</p>