postgresql delete duplicated rows
Deleting duplicates
使用window function row_number
对数据partition
举例:
isnp=# create table student (id serial, name text, age int); isnp=# \d student; isnp=# with cte as (select *, round(random()*100) as d from generate_series(1,10000) as r) insert into student (name, age) select 'lmy'||r, d from cte; ### genetate duplicate row isnp=# insert into student (name, age) select name, age from student where 100<id and id<200; isnp=# with xxx (id, name, age, rn) as (select *, row_number() over(partition by name order by id) rn from student) delete from student where id in (select id from xxx where rn > 1);
相关推荐
lerdor 2020-08-31
谢育政 2020-07-28
mrandy 2020-07-04
sunnyxuebuhui 2020-06-16
Laxcus大数据技术 2020-06-13
fyggzb 2020-06-10
vivenwan 2020-06-06
zhangwentaohh 2020-05-25
韩学敏 2020-05-25
Andrea0 2020-05-17
xx0cw 2020-05-16
林大鹏 2020-05-12
CHINA华军 2020-05-11
talkingDB 2020-05-05
lysanderK 2020-04-19
zuixin 2020-04-19
jimgreatly 2020-04-10