-
Getting row information in Oracle
I am working on a query:
Get the item_id, order_id, price from the order_line table where the price for an individual item's order is greater than the average of all orders for the item.
Here is what I have so far to get the average for all of the items:
SELECT order_id, AVG(price) FROM order_line
GROUP BY order_id
What can I do from here to get all of the prices (and item ids) where the price is greater than the average for each value?
-
How about this.
select a.item_id, a.rder_id, a.price
from order_line a,
(SELECT item_id, AVG(price) price FROM order_line
GROUP BY item_id) b
where a.item_id = b.item_id
and a.price > b.price
-
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
|
|