postgresql 删除重复数据
侧边栏壁纸
  • 累计撰写 50 篇文章
  • 累计收到 0 条评论

postgresql 删除重复数据

admin
2021-10-19 / 0 评论 / 423 阅读 / 正在检测是否收录...

方法一 普通方法

DELETE 
FROM
    bookmarks A 
WHERE
    A.ID NOT IN ( SELECT MIN ( ID ) FROM bookmarks GROUP BY "user_id", "product_id", "is_from_vuclip" );

方法二 速度快

DELETE 
FROM
    bookmarks A 
WHERE
    A.ID = ANY (
        ARRAY (
        SELECT ID 
        FROM
            ( SELECT ROW_NUMBER ( ) OVER ( PARTITION BY "user_id", "product_id", "is_from_vuclip" ), ID FROM bookmarks ) T 
        WHERE
            T.ROW_NUMBER > 1 
        ) 
    );
0

评论 (0)

取消