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
https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/
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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.