如何在 psql 中使用 row_number() 从 table 中删除重复项?
How to delete the duplicates from the table using row_number() in psql?
我已经编写了以下查询,我正在使用 greenplum db 和 dbeaver 来实现。
with cte as
(select
*,
row_number() over(partition by first_name order by roll_num) row_num
from table_name
where roll_num in ('0011'))
delete from cte where row_num>1;
以上查询返回错误。请有人能帮我一下!
请尝试这样对我有用:
select * from tablename as t
where exists
( select *
from tablename as d
where d.ctid > t.ctid
and d.* is not distinct from t.*
) ;
delete from tablename as t
where exists
( select *
from tablename as d
where d.ctid > t.ctid
and d.* is not distinct from t.*
) ;
这个怎么样:
我已经编写了以下查询,我正在使用 greenplum db 和 dbeaver 来实现。
with cte as
(select
*,
row_number() over(partition by first_name order by roll_num) row_num
from table_name
where roll_num in ('0011'))
delete from cte where row_num>1;
以上查询返回错误。请有人能帮我一下!
请尝试这样对我有用:
select * from tablename as t
where exists
( select *
from tablename as d
where d.ctid > t.ctid
and d.* is not distinct from t.*
) ;
delete from tablename as t
where exists
( select *
from tablename as d
where d.ctid > t.ctid
and d.* is not distinct from t.*
) ;
这个怎么样: