Penso che la tua logica stia usando merge e row_number() è sulla buona strada (sebbene, presumibilmente, la partition by non è necessaria, poiché stai già filtrando sulla città`). L'ho esteso con una logica aggiuntiva per gestire le date:
-
l'iniziale
effective_dt_fromeeffective_dt_tofinale dovrebbe essere lasciato intatto -
nel mezzo, vuoi aumentare le date giorno per giorno a partire da
'2017-01-01'.
Domanda:
merge into test t
using (
select
t.*,
row_number() over(order by loc_sid asc) rn,
count(*) over() cnt
from test t
where city = 'Chicago'
) t1
on (t1.loc_sid = t.loc_id)
when matched the update set
t.version = t1.rn,
t.effective_dt_from =
case
when rn = 1 then t.effective_dt_from
else date '2017-01-01' + rn - 2
end,
t.effective_dt_to =
case
when rn = cnt then t.effective_dt_to
else date '2017-01-01' + rn - 1
end