我有两张桌子:"Trades_Imported“
Id TradeId Price OrderType
1 01-01-20 ABC 525 B
2 01-01-20 ABC 275 S
3 01-01-20 ABC 288 S和"Trades_Grouped“
TradeId EntryPrice ExitPrice
01-01-20 ABC 525 563 (SUM of all Sales Order of TradeId) 我不知道怎么说:
EntryPrice =求和(价格)若OrderType = B;
ExitPrice =求和(价格)若OrderType = S;
因为我已经按TradeId分组了.有什么想法吗?我遗漏了什么?
提前谢谢(我正在使用MySql)
发布于 2020-11-02 10:56:14
您似乎希望有条件的聚合:
select tradeid,
sum(price) sum_price,
sum(case when ordertype = 'B' then price else 0 end) sum_price_b,
sum(case when ordertype = 'S' then price else 0 end) sum_price_s
from trades_imported
group by tradeidhttps://stackoverflow.com/questions/64644129
复制相似问题