https://leetcode.com/problems/capital-gainloss/
Capital Gain/Loss - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
SELECT stock_name, SUM(
CASE WHEN operation = 'Buy' THEN -price
ELSE price
END
) AS capital_gain_loss
FROM Stocks
GROUP BY stock_name
|
cs |