title: Cumulative average mysql php
body: <p>I have a table name <code>meal</code></p>
  
  <pre><code>id name carbs protein fat
  
  1  one   10    30      18   
  2  one   17    4        2
  3  one   27    6        7
  </code></pre>
  
  <p>Now I want to get Cumulative Average of carbs</p>
  
  <p>my query is </p>
  
  <pre><code>SELECT (100*(sum(m.carbs)/(sum(m.carbs)+sum(m.fat)+sum(m.protein))))AS Percantage_carbs FROM `meal` AS m
  </code></pre>
  
  <p>My query gives result 52.2580645</p>
  
  <p>But I t will be</p>
  
  <p>52.8848076</p>