My query looks like this
select A.player_uuid, MAX(distinct(A.update_date) ::date) filter (where A.payment_type in ('Deposit','DEPOSIT'))as Last_DEP_DATE, MAX(distinct(A.update_date) ::date) filter (where A.payment_type in ('Deposit','DEPOSIT'))-30 as Last_DEP_DATE2 from Mytable A where A.payment_method not in ('NULL','Manual','manual') and A.status='COMPLETED' group by A.player_uuid
And now I need sum of deposits, from 30 days before last deposit to last deposit. in other words last active month of player (player_uuid) .
Deposit amount is stored in A.amount column