DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: order by non-table attribute help

  1. #1
    Join Date
    Jan 2006
    Posts
    2

    order by non-table attribute help

    Hi, I wonder if someone could help me out.

    I have created the following query:

    SELECT order_id,sum(suggested_whlsl_price*quantity)
    FROM order_item, product
    WHERE product.p_id = order_item.product_id
    GROUP BY order_id


    This displays my order ID numbers along with the total value of the order. However I can only get it to order by order_id.

    What I want to actually do is order it by the value of the order and only return, say the first 5 rows, so in effect im selecting the 5 most expensive orders from the database.

    Now I'm still fairly new to Oracle, however I have been studying hard and I'm either missing something fairly obvious or I'm getting brain freeze because I've been trying for hours to get it to work now.

    If someone could help me out with this I would HUGELY appreciate it

    Thank you in advance
    Rich

  2. #2
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    You could add either:

    ORDER BY sum(suggested_whlsl_price*quantity) DESC
    . . . or
    ORDER BY 2 DESC

    then wrap it all in a SELECT statement to get the first 5 rows.
    "The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman

  3. #3
    Join Date
    Jan 2006
    Posts
    2
    Thanx very much bud,

    appreciated

Posting Permissions

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


Click Here to Expand Forum to Full Width