update life_expectancy
set startlife = r_startlife
from (
with recursive demo( rno, r_probsurv, r_startlife) as
(select 0, 1::numeric, 100000::numeric -- prime the recursion
union all
select id,probsurv, r_probsurv*r_startlife
from life_expectancy
join demo
on (id = (select min(id) -- since I do trust autogenerated ids
from life_expectancy -- to actually be in perfect sequence
where id > rno))
)
select rno,r_probsurv, round(r_startlife) r_startlife
from demo
) s
where id = rno; The above query is working for one single phr_makkal_district. But I need to execute this query for all phr_makkal_district.
Need to apply condition in this query. Once reach the age_range 0-1 Year need to update 100000(defaut value) in the startlife columns for the next phr_makkal_district.