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. POJ1182--食物链(经典并查集)并查集看不出来系列2

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65906   Accepted: 19437 Description ...

  2. HDU2216:Game III(BFS)

    Game III Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  3. android 学习之RecyclerView

    RecyclerView:ListView的升级版,它提供了更好的性能而且更容易使用.该控件是一个可以装载大量的视图集合,并且可以非常效率的进行回收和滚动.当你list中的元素经常动态改变时可以使用R ...

  4. U3D脚本开发基础

    1.MonoBehaviour类,定义了对各种特定事件的脚本响应函数.这些函数均以On做开头. 2.U3D中常用的组件及对应变量名如下: Transform(transform),Rigidbody( ...

  5. struts体系结构

    问题:   为什么 invoke()方法,一旦执行,表示action方法执行完毕,jsp页面已经处理完毕: 其返回值再修改无意义,不影响结果?? 解释: 着重看如下颜色的字: ■ ■ 官方文档有明确的 ...

  6. Android Studio 提示Error running app: No Android facet found for app

    错误解决办法如下: 可以通过以下几个步骤解决该问题: 1) 点击菜单File -> 选择Project Structure, 或使用快捷键 (Ctrl+Alt+Shift+S) 打开”Proje ...

  7. audio,video标签

    <html><head lang="en"> <meta charset="UTF-8"> <title>< ...

  8. MJRefresh

    automaticallyChangeAlpha 下拉或上拉时,文字颜色逐渐加深

  9. 创建控制器的3种方式、深入了解view的创建和加载顺序

    转载自:http://blog.csdn.net/weisubao/article/details/41012243 (1)创建控制器的3种方式 - (BOOL)application:(UIAppl ...

  10. 兼容性,float

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