sql - Update Duplicate Records -
i have column store table, table_hana below data in hana db:
t_id1 t_id2 t_desc t_rn 1 1 aaa ? 1 1 bbb ? 1 2 ccc ? 1 3 ddd ? 1 3 eee ? i need group them t_id1 , t_id2 , update t_rn column of group sequential value shown below:
t_id1 t_id2 t_desc t_rn 1 1 aaa 1 1 1 bbb 2 1 2 ccc 1 1 3 ddd 1 1 3 eee 2 since table huge(millions of records), looking solution performance. please suggest.
tia
the first question whether need update. following query returns want:
select h.*, row_number() on (partition t_id1, t_id2 order t_desc) t_rn table_hana h; this may sufficient.
the update expensive:
update table_hana h set t_rn = (select count(*) table_hana h2 h2.t_id1 = h.t_id1 , h2.t_id2 = h.t_id2 , h2.desc <= h.desc ); an index on table_hana(t_id1, t_id2, t_desc) should both these queries.
Comments
Post a Comment