Jump to content

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:

 

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 by neilfurry
Link to comment
https://forums.phpfreaks.com/topic/301496-help-mysql-percentage-getting-to-work/
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.