开发者

Oracle - How to calculate profit that is above average

开发者 https://www.devze.com 2023-03-18 22:44 出处:网络
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 nee

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消