i want create table subset of records master table. example, have:
id name code 1 peter 73 2 carl 84 3 jack 73
i want store peter , carl not jack because has same peter's code. need hight performance because have 20m records.
i try this:
select id, name, distinct(code) new_tab old_tab (conditions)
but don't work.
assuming want pick row maximum id
per code
, should it:
insert new_tab (id, name, code) (select id, name, code ( select id, name, code, rank() rnk on (partition code order id desc) old_tab rnk = 1 ) )
and minimum id
per code, change sort order in rank desc asc:
insert new_tab (id, name, code) (select id, name, code ( select id, name, code, rank() rnk on (partition code order id asc) old_tab rnk = 1 ) )
Comments
Post a Comment