Oracle - How to calculate profit that is above average
I have a table that contains items, buyprice, and sellprice. I need to figure out how to return which items were sold for a profit above average. I realize 开发者_如何转开发that for each item that I need to calculate sellprice-buyprice to get the profit. I then need to take the profit from each item and calculate the average profit of all of the items. I then need to return the items that have profits that are above that average. I have tried various subselects and I just can't seem to figure out how to return what I want.
Seems simple enough:
SELECT * FROM TBL WHERE sellprice-buyprice > (SELECT AVG(sellprice-buyprice) FROM TBL )
Am i missing something?
精彩评论