Skip to content

Commit 711ad1a

Browse files
authored
Create capital-gainloss.sql
1 parent a8075fd commit 711ad1a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

MySQL/capital-gainloss.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT stock_name,
5+
Sum(CASE
6+
WHEN operation = 'Buy' THEN -price
7+
ELSE price
8+
END) AS capital_gain_loss
9+
FROM stocks
10+
GROUP BY stock_name
11+
ORDER BY NULL;

0 commit comments

Comments
 (0)