You need to sum() s:
select year_num, age_bucket, sum(num_cust), sum(sum(num_cust)) over (partition by year_num)
Why? Well, the window function does not perform aggregation. The argument must be an expression that can be evaluated after group by (because it is an aggregation request). Since num_cust not a group by key, it needs an aggregation function.
Perhaps this is more understandable if you used a subquery:
select year_num, age_bucket, sum_num_cust, sum(sum_num_cust) over (partition by year_num) from (select year_num, age_bucket, sum(num_cust) as sum_num_cust from foo group by year_num, age_bucket ) ya order by 1, 2;
These two queries do the same. But with a subquery, it should be more obvious why you need additional aggregation.
source share