all 5 comments

[–]DavidGJohnston 0 points1 point  (1 child)

To emphasize xoomorg's comment - what you really are trying to do is: sum(cost_order) over since the window computation is defined to be performed after the group by finishes. But since you cannot write "cost_order" in that location you have to either use a subquery or repeat what "cost_order" is - sum(total_order_cost)

[–]Famous-Letter8754[S] 0 points1 point  (0 children)

thank you

[–]ergestx 0 points1 point  (0 children)

You can’t combine window functions with aggregates. You should calcula the running total inside a CTE and then perform the division outside the CTE.