How to make a custom group in sql
Here is a table:
ID TYPE AMOUNT
-- ---- ------
1 sell 50
1 sell 100
1 buy 200
2 sell 50
2 buy 100
How to write a SQL query that returns the following result:
ID TOTAL
-- -----
1 50
2 50
I think I need it group by id
, but I'm not sure how to do the "subtraction" on the "sell".
My db is an oracle by the way.
Thank you Relationship
+3
source to share