Looking at the description, it seems like you want a group based on negative and positive quantity
along with date
.
You have not tagged your question with any database but you can use the standard sql case .. when
as follows:
Select date, price, sum(quantity) as quantity
From your_table t
Group by date, price, case when quantity < 0 the 1 else 2 end;
If you dont want the result to be groupped by price
then you can remove the price
from the group by
clause and use max(price)
or any aggregate function as per your requirement in the select
clause.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…