1393. Capital Gain/Loss

https://leetcode.com/problems/capital-gainloss

Description

Table: Stocks

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| stock\_name    | varchar |
| operation     | enum    |
| operation\_day | int     |
| price         | int     |
+---------------+---------+
(stock\_name, operation\_day) is the primary key for this table.
The operation column is an ENUM of type ('Sell', 'Buy')
Each row of this table indicates that the stock which has stock\_name had an operation on the day operation\_day with the price.
It is guaranteed that each 'Sell' operation for a stock has a corresponding 'Buy' operation in a previous day.

Write an SQL query to report the Capital gain/loss for each stock.

The capital gain/loss of a stock is total gain or loss after buying and selling the stock one or many times.

Return the result table in any order.

The query result format is in the following example:

ac

Last updated

Was this helpful?