title: How to subtract two calculated fields from the same table in MySQL?
body: <pre><code>SELECT   *, 
           SUM(price+shipping+paypalfee+storefee) AS totalcost, 
           customerpaid                           AS totalrevenue, 
           (totalcost - totalrevenue)             AS profit 
  FROM     tblsales 
  GROUP BY orderno 
  HAVING   " . $having . " 
  ORDER BY $sort $order 
  LIMIT    $offset,$rows
  </code></pre>
  
  <p>If I omit <code>(totalcost - totalrevenue) as profit</code> the query works fine. How could I calculate PROFIT in the same query using totalcost and totalrevenue?</p>