I have a table:
key product_code cost 1 UK 20 1 US 10 1 EU 5 2 UK 3 2 EU
You could use BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW to achieve that without a self join.
BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Code as below:
SELECT a, SUM(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;