当我将具有相同CATEGORY
值的记录组合在一起时,我想找到差异(利润和损失)(例如,将组合A'并且将组合C')。
答案 0 :(得分:2)
我认为你想要条件聚合:
A["b"]
答案 1 :(得分:1)
Select category, buy.amt-sell.amt ProfitorLoss
from
(SELECT sum(price*quantity) amt, Category
FROM yourtable
WHERE side = 'BUY'
GROUP BY Category) buy,
(SELECT sum(price*quantity) amt, Category
FROM yourtable
WHERE side = 'SELL'
GROUP BY Category) sell
where buy.category = sell.category