Write a solution to report the Capital gain/loss for each stock.
The Capital gain/loss of a stock is the total gain or loss after buying and selling the stock one or many times.
Return the result table in any order.
The result format is in the following example.
Sell
인 값들의 합 - Buy
인 값들의 합으로 하려했는데IF
을 잘 사용하면 차 계산을 쉽게 할 수 있었다.SELECT stock_name,
SUM(IF(operation = 'Sell', price, -price)) AS capital_gain_loss
FROM Stocks
GROUP BY 1