MySQL Forums
Forum List  »  Newbie

Re: Could anyone help me to write a query to do the following:
Posted by: Matthew Southgate
Date: October 06, 2015 02:38PM

Does this do it?

SELECT ID_, Resourceid
, SUM(AmountBought)/SUM(CASE WHEN Action = 'buy' THEN 1 ELSE 0 END)-SUM(AmountSold)/SUM(CASE WHEN Action = 'sell' THEN 1 ELSE 0 END) AS Profit
FROM TABLE26
GROUP BY ID_, Resourceid

I created a bit more dummy data to test this.

Options: ReplyQuote


Subject
Written By
Posted
Re: Could anyone help me to write a query to do the following:
October 06, 2015 02:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.