select a.`security`,
case when b.side is not null
then (b.price-a.price) * b.quantity
else '' end "realized_p&l"
from tbl a
left join tbl b
on a.`security`=b.`security` and b.side='SELL'
where a.side='BUY'
result:
security realized_p&l
MSFT -1000
AAPL
1条答案
按热度按时间vd2z7a6w1#
实际价格是卖出价减去买入价乘以卖出数量。