美文网首页
mysql删除重复列的记录

mysql删除重复列的记录

作者: xun2019 | 来源:发表于2020-11-24 11:00 被阅读0次
    使用select方式

    无法执行

    
    delete from xxx as a,
    (
    select *,min(id) from xxx group by userId,coint having count(1) > 1
    ) as b where a.userId = b.userId and a.coint=b.coint and a.id > b.id;
    

    查询可以

    
    select * from xxx as a,
    (
    select *,min(id) from xxx group by userId,coint having count(1) > 1
    ) as b where a.userId = b.userId and a.coint=b.coint and a.id > b.id;
    

    使用聚合方式

    
    Select *
    FROM xxx d inner
    JOIN coinapiset d1 ON d1.userId = d.userId AND d1.coint = d.coint AND d1.id < d.id;
    

    可以删除

    
    Delete d
    FROM xxx d inner
    JOIN xxx d1 ON d1.userId = d.userId AND d1.coint = d.coint AND d1.id < d.id;
    

    相关文章

      网友评论

          本文标题:mysql删除重复列的记录

          本文链接:https://www.haomeiwen.com/subject/htliiktx.html