title: How to sum based on field value (mysql)
body: <p>I got this table named <code>tb_stock</code></p>
  
  <pre><code>ID AMOUNT FLAG LAST_AMOUNT
  1   5     N    0                
  2   0     Y    8                
  3   0     Y    7                
  4   6     N    0
  </code></pre>
  
  <p>Right now i want to sum the value based on the FLAG value. For example if the FLAG values is N, it will sum from the AMOUNT field and if the FLAG value is Y, it will sum from the LAST_AMOUNT field.</p>
  
  <p>So the total amount would be 26 (5 + 8 + 7 + 6).</p>
  
  <p>Is this can be achieve with just use mysql or it will involve php as well?</p>
  
  <p>Thanks.  </p>