SELECT
if('1000'>plan_limit_max,'1000'-plan_limit_max,0) as 'Overage',
if(`per_hour_cost`='0', `per_period_cost`+'10'*`Overage`, per_hour_cost*720) AS 'Total'
FROM `service_price`
order by Total asc
;
There is an error with Overage at line 3
Error Code: 1054. Unknown column 'Overage' in 'field list'
Is there a way to do what I want with one query? I want to order results by total price, but to calculate it I have to calculate the usage exceeds the limit.
I know there should be other ways to do it, use more than one queries, create views, etc.. I just wonder if there is a simpler query for this.
'1000') ?