I have the following data:
Date ID Type Cost
May 01 a A 1
May 01 b A 2
May 01 c B 3
May 01 d B 4
May 02 e A 5
May 02 f A 6
May 02 g B 7
May 02 h B 8
I want a query that shows
Date Type CostPercentage
May 01 A (1+2) / (1+2+3+4)
May 01 B (3+4) / (1+2+3+4)
May 02 A (5+6) / (5+6+7+8)
May 02 B (7+8) / (5+6+7+8)
What I currently have is
select Date, Type, sum(cost)
from mytable
group by Date, Type
I would really want to show the percentage, but that will involve deviding another number which is itself an aggregation.
How am I suppose to do that?
EDITED to reflect my real problem. I over simplified it before.
You could use a subquery:
Link to working example @odata.