I have the following table:
id | kwh | cost
---------------------
1 | 10 | 8.95
2 | 20 | 0
3 | 100 | 16.54
I need to get the average cost.
If the cost is still the default (0), the cost value is calculated with the following formula: (7.87 + (kwh * 8.19)/100) * 1.03
So id 2's cost will be estimated at 9.79 for an average cost of 35.28/3 = 11.76.
Is there a mySQL query that will calculate the cost if the column has the default value and use inputed value otherwise?