Hi Programmers, Welcome to Ozanecare and this article i’m going to write queries to find out cumulative salary in postgresql database. Calculating Running Total or cumulative salary with OVER clause and Partition By. with the help of partition by we can divided groups and we can calculate cumulative sum of every groups. let’s see the queries.
1.To view Table records. we show write select * from table name. see below image.
2.To calculate cumulative sum we should use sum aggregator function. over by clause and make Sal column in order.but the below query find duplicate salaries then cumulative sum also created duplicate. see below image.
3.If we include RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW .it also return same output when that found duplicate Sal then cumulative salary also return duplicate. see below image.
4.If we include ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW .it also return unique cumulative sum
when that found duplicate Sal then cumulative salary return unique. see below image.
5.we can find out cumulative sum with each and every group by using partition by clause. see below image.