Jump to content

[SOLVED] SQL Alias calculations


nealios

Recommended Posts

Hello,

 

I am currently trying to make a invoice creator using php myql. Im currently using the below statement to use the price stored in my db to calculate VAT(tax). 

 

SELECT Price * 0.175 AS VAT Total FROM Job WHERE JobID = $JobID";

 

Is it possible to do another calculation with an alias. ideally i want to add the VAT alias and the price together to output a Total.

 

I tried this to no avail

 

SELECT Price * 0.175 AS VAT, Price + VAT AS Total FROM Job WHERE JobID = $JobID";

 

Where am i going wrong?

 

Many thanks

 

Link to comment
Share on other sites

Fear not i over came the problem by using a second alias rather than trying to calculate the first.

 

"SELECT Price * 0.175 AS VAT, Price * 1.175 AS Total FROM Job WHERE JobID = $JobID";

 

 

How do i format the output? its currently being displayed like 8.75000 but i want to remove the zeros. 

Link to comment
Share on other sites

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.