https://leetcode.com/problems/capital-gainloss/description/
Capital Gain/Loss - LeetCode
Capital Gain/Loss - Table: Stocks +---------------+---------+ | Column Name | Type | +---------------+---------+ | stock_name | varchar | | operation | enum | | operation_day | int | | price | int | +---------------+---------+ (stock_name, operation_day) i
leetcode.com
1
2
3
4
5
6
7
8
9
10
|
# Write your MySQL query statement below
select stock_name,
sum(
case
when operation = 'Buy' then -price
else price
end
) as 'capital_gain_loss'
from Stocks
group by stock_name
|
cs |
반응형
'SQL' 카테고리의 다른 글
leetcode 1378. Replace Employee ID With The Unique Identifier (0) | 2023.04.06 |
---|---|
leetcode 1683. Invalid Tweets (0) | 2023.04.06 |
hackerrank Occupations (0) | 2022.11.13 |
leetcode 1050. Actors and Directors Who Cooperated At Least Three Times (0) | 2022.07.26 |
leetcode 1084. Sales Analysis III (0) | 2022.07.18 |
댓글