LeetCode 1393. Capital Gain/Loss
考点难度DatabaseMedium
题目 Write an SQL query to report the Capital gain/loss for each stock.
The Capital gain/loss of a stock is the total gain or loss after buying and selling the stock one or many times.
Return the …
题目链接:http://lightoj.com/volume_showproblem.php?problem1393
2011 was a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, some even went through surgery only to have 11-11-11 as their childs birth date. Ho…
两种解法,第一种很微妙 一个if解决 sum是字段内求和,if标签进行判断,如果是买入就自动变负数加和,如果是售出就自动加和
select stock_name,sum(if(operationBuy,-price,price)) as capital_gain_loss
from Stocks
group by sto…