美文网首页
182. Duplicate Emails

182. Duplicate Emails

作者: jluemmmm | 来源:发表于2021-09-29 10:07 被阅读0次

    找到重复的email链接

    Table: Person

    +-------------+---------+
    | Column Name | Type |
    +-------------+---------+
    | Id | int |
    | Email | varchar |
    +-------------+---------+

    Input:
    Person table:
    +----+---------+
    | Id | Email |
    +----+---------+
    | 1 | a@b.com |
    | 2 | c@d.com |
    | 3 | a@b.com |
    +----+---------+
    Output:
    +---------+
    | Email |
    +---------+
    | a@b.com |
    +---------+

    使用 GROUPBY 和临时表

    • Runtime: 340 ms, faster than 46.56%
    • Memory Usage: 0B, less than 100.00%
    SELECT Email FROM
    (
      SELECT Email, COUNT(Email) AS num
      FROM Person
      GROUP BY Email
    ) AS statistic
    WHERE num > 1
    

    使用GROUPBY 和 HAVING

    • Runtime: 342 ms, faster than 45.46%
    • Memory Usage: 0B, less than 100.00%
    SELECT Email
    FROM Person
    GROUP BY Email
    HAVING COUNT(Email) > 1
    

    相关文章

      网友评论

          本文标题:182. Duplicate Emails

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