SUM selected columns using alias and group by
<p>I'm trying to perform calculations on select columns using aliases and a grouping by. Query is below(problem on line before the from): </p>

<pre><code>select r.res_id, 
    r.arrive_date,
    r.depart_date,
    r.res_type,
   if(DATEDIFF(r.depart_date, r.arrive_date) &gt;29, 'LT', 'ST') as 'StayType',
   SUM(r.rent + r.fee_arr_early + r.fee_dep_late + r.fee_peace_waiver + r.fee_pool + r.city_tax + r.fee_cleaning + r.fee_pet + r.fee_tshirt + r.fee_misc + r.fee_non_tax + r.fee_processing + r.fee_travel_ins + r.fee_event + r.fee_cancel) as 'folioTotal',
   coalesce((select SUM(g.amount) from guest_payments as g where g.resId = r.res_id and charge_type = 'charge' and approved = 'Y'),0) as 'payments',
   coalesce((select SUM(g.amount) from guest_payments as g where g.resId = r.res_id and charge_type = 'credit' and approved = 'Y'),0) as 'credits',
    (SUM('folioTotal') - SUM('payments') + SUM('credits')) as 'folioBalance'
from reservations as r
    join guest_payments as g
        on r.res_id = g.resId
        group by r.res_id
</code></pre>

<p>I've tried putting this inside another sum with the same outcome.</p>