• Without the DDL and some data I'm not going to spend time trying any code out but wouldn't SUM with the OVER clause do what you need, in the first query?