nealios Posted November 18, 2007 Share Posted November 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/ Share on other sites More sharing options...
nealios Posted November 18, 2007 Author Share Posted November 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/#findComment-393966 Share on other sites More sharing options...
toplay Posted November 18, 2007 Share Posted November 18, 2007 http://dev.mysql.com/doc/refman/5.0/en/precision-math-rounding.html Quote Link to comment https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/#findComment-393979 Share on other sites More sharing options...
nealios Posted November 18, 2007 Author Share Posted November 18, 2007 Thanks for the reply, though im not sure where i can apply this to my statement Quote Link to comment https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/#findComment-393991 Share on other sites More sharing options...
toplay Posted November 18, 2007 Share Posted November 18, 2007 "SELECT ROUND(Price * 0.175, 2) AS VAT, ROUND(Price * 1.175, 2) AS Total FROM Job WHERE JobID = $JobID"; Quote Link to comment https://forums.phpfreaks.com/topic/77832-solved-sql-alias-calculations/#findComment-394017 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.