I need to build a new column in my existing table.
So there are two columns, 
'cmg' and 'effdate' and I need to create a new column called 'enddate'.
So for a particular cmg, 
the max of eff\_date = current date 
and the dates in next row should be equal to the date in the previous row - 1.

For example,

```
cmg |  effdate
1      23/10/2018
1      1/10/2018
1      1/1/2018
3      1/12/2018
3      1/3/2018

```

I need to 1st filter the rows based on the values in cmg column and then get enddate as below: 

```
cmg |  effdate   |      enddate  
1      23/10/2018       currentdate 
1      1/10/2018        22/10/2018
1      1/1/2018         30/9/2018
3      1/12/2018        currentdate
3      1/3/2018         30/11/2018

```