본문 바로가기
SQL

leetcode 1393. Capital Gain/Loss

by 무적김두칠 2023. 1. 26.

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
반응형

댓글