www.webdeveloper.com
Results 1 to 2 of 2

Thread: Alias Question MySql

  1. #1
    Join Date
    Nov 2007
    Posts
    17

    Alias Question MySql

    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
    Last edited by psdeveloper; 11-01-2008 at 07:25 AM. Reason: add

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    its more because quantity1 is an alias for aggregate reults. youre trying to sum a sum which doesnt work

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles