neilfurry Posted July 18, 2016 Share Posted July 18, 2016 (edited) hi there, can i ask some help please. i need to get the addon percentage on my database... add on is being computed based on the difference between an invoice and estimate. my query goes like this: SELECT COUNT(estimate) as est, SUM(invoice-estimate) as addons, SUM(addons / est) * 100 as Percentage FROM tblestimates What is the best way to do this? i know that i cant use aliases on the computation i made. Thank you Edited July 18, 2016 by neilfurry Quote Link to comment https://forums.phpfreaks.com/topic/301496-help-mysql-percentage-getting-to-work/ Share on other sites More sharing options...
Barand Posted July 18, 2016 Share Posted July 18, 2016 Use the expression instead of its alias in the calculation. SELECT SUM(invoice - estimate) / SUM(estimate) * 100 as percent Note SUM(estimate) and not COUNT. Multiplying an average by 100 is not the best way. Quote Link to comment https://forums.phpfreaks.com/topic/301496-help-mysql-percentage-getting-to-work/#findComment-1534588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.