Write a SQL query to find all duplicate emails in a table named Person.

+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+

For example, your query should return the following for the above table:

+---------+
| Email |
+---------+
| a@b.com |
+---------+

Note: All emails are in lowercase.

where里面不能用count,因为where后面跟的条件必须是一行可以确定的,而count需要数一下table中一共有多少行,显然不满足这个要求。多以需要用group by + having。

# Write your MySQL query statement below
select Email from Person GROUP BY Email HAVING count(Email) > 1

常见思路,由于是在table中按某个条件选择一部分row,而且这个条件牵扯到其他row。常用的方法是使用table的多个copy。

# Write your MySQL query statement below
select distinct p1.Email from Person p1, Person p2 where p1.Email = p2.Email and p1.Id != p2.Id

Leetcode 182. Duplicate Emails的更多相关文章

  1. leetcode 182. Duplicate Emails having的用法 SQL执行顺序

    https://leetcode.com/problems/duplicate-emails/description/ 首先sql的执行顺序是 from-->where-->group b ...

  2. LeetCode 182. Duplicate Emails (查找重复的电子邮箱)

    题目标签: 题目给了我们一个 email 的table,让我们找到重复的 email. 可以建立 Person a, Person b, 找到两个表格中,emai 相等 但是 id 不同的 email ...

  3. [LeetCode] Delete Duplicate Emails 删除重复邮箱

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  4. [LeetCode] 182. Duplicate Emails_Easy tag: SQL

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  5. 【SQL】182. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  6. 182. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  7. LeetCode - Delete Duplicate Emails

    Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping ...

  8. LeetCode——Delete Duplicate Emails(巧用mysql临时表)

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  9. [LeetCode] Duplicate Emails 重复的邮箱

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

随机推荐

  1. ajax2016/4/15 post与get

    post方式,数据放在send()里面作为参数传递 xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); ...

  2. 给input元素添加float. 去除IE6 下input的空隙

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. 初探JavaScript魅力(二)

    行为,样式,结构三者分离(javascript, css, html),不要在行间加行为,样式 样式优先级:*<标签<class<ID<行间 style与className,如 ...

  4. js框架——angular.js(5)

    1. 3种过滤方式 <html> <head> <meta charset='utf-8'> <script src="js/angular.js& ...

  5. jq的遍历节点

    1.child()方法 该方法用于取得匹配元素的子元素集合 2.next() 该方法用于取得匹配元素后面紧邻的同辈元素, 3.prev() 该方法用于取得匹配元素前面紧邻的同辈元素 4.sibling ...

  6. 详细讲解MOSFET管驱动电路(转)

    作者:   来源:电源网 关键字:MOSFET 结构 开关 驱动电路 在使用MOS管设计开关电源或者马达驱动电路的时候,大部分人都会考虑MOS的导通电阻,最大电压等,最大电流等,也有很多人仅仅考虑这些 ...

  7. Abandoned country

    Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  8. 环境:win7+ie8 IE8的F12不起作用,原因如下:

    1.先按下F12 2.再按下CTL+P,此时调试框将出现在屏幕下方. 3.再次点击CTL+P 4.此时在任务栏上的到IE8的图标,将会看到调试框,右击最大化,此时调试框是最大化状态. 5.然后再慢慢的 ...

  9. Android开发之InstanceState详解(转)---利用其保存Activity状态

    Android开发之InstanceState详解   本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...

  10. Python3基础 函数名.__doc__显示一个函数的单行与多行函数文档

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...