-
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
-
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|