美文网首页
2020-04-13

2020-04-13

作者: DUYAN_bc77 | 来源:发表于2020-04-13 15:52 被阅读0次

    删除重复保留最大或最小

    Screen Shot 2020-04-13 at 2.51.56 PM.png

    Solution 1

    DELETE P1
    FROM Person AS P1, Person AS P2
    WHERE P1.Email=P2.Email AND P1.Id>P2.Id
    

    自连接,删除Email相同,但是ID大的记录

    Solution 2

    DELECT FROM PERSON
    WHERE id not in (SELECT P1.id not in
           ((SELECT min(Id) as id 
           From Person
          Group by Email) as P1)
    

    相关文章

      网友评论

          本文标题:2020-04-13

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