Click to See Complete Forum and Search --> : Alias Question MySql


psdeveloper
11-01-2008, 06:22 AM
I have the following query that works...

SELECT tOrdersDetail.ProductId , SUM(tOrdersDetail.quantity) as Quantity1,SUM( tOrdersDetail.Price * Quantity) as Price1,tProduct.UnitPrice as uCost,SUM(Quantity * tProduct.UnitPrice) as Total_Cost .... -> wont work if i add this on ,( Quantity1/Price1) as Average_Cost
FROM tProduct
INNER JOIN tOrdersDetail
ON tOrdersDetail.ProductId=tProduct.ProductId
GROUP BY ProductId
LIMIT 0 , 30

I need to preform 2 more calculations in the result set...
My thought was to just add this and i can mamke calucation based on alias name....but no luck
( Quantity1/Price1) as Average_Cost
( Total_Cost/Price1) as Average_Cost

I get an error invalied field name...thanks

chazzy
11-01-2008, 07:06 PM
its more because quantity1 is an alias for aggregate reults. youre trying to sum a sum which doesnt work