Jump to content

Help MySQL percentage getting to work

Recommended Posts

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:



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 by neilfurry

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.