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. HDU 1824 Let's go home

    2-SAT,根据题意建好图,求一下强联通分量,判断一下就可以了 #include<cstdio> #include<cstring> #include<cmath> ...

  2. 第11章 类的高级特性--final

    1.final变量 (1)final关键字可用于变量声明,一旦该变量被设定,就不可以再改变该变量的值.通常,由final定义的变量为常量.例如:final double PI=3.14; final关 ...

  3. memcached添加IP白名单,只允许指定服务器调用

    由于memcached默认安装是不用配置密码的(具体的密码配置我也没怎么研究,据说是有的,大家感兴趣去找一找) 然而memcached链接也是非常简单的 linux命令链接使用  Telnet IP地 ...

  4. 转 区别 getChildFragmentManager getSupportFragmentManager

    The definition of getChildFragmentManager() is: Return a private FragmentManager for placing and man ...

  5. SQL Server 2008登录问题(错误 233和18456)解决方法

    今天使用 SQLSERVER2008 先遇到了233 错误,后又遇到了 18456 ,从网上找到了解决方法,具体如下: 问题一 : 已成功与服务器建立连接,但是在登录过程中发生错取.(provider ...

  6. audio,video标签

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

  7. 把自己的电脑做服务器发布tomcat的项目外网访问

    1.首先你要确定你有一个外网ip地址.如果你分配到的是一个局域网IP地址需要经过一系列的转换为外网ip地址,然后继续下面操作. 2.拿到外网IP地址,进行tomcat的server.xml文件的配置. ...

  8. MySQL数据类型:SQL_MODE设置不容忽视

    [IT168 技术]SQL_MODE可能是比较容易让开发人员和DBA忽略的一个变量,默认为空.SQL_MODE的设置其实是比较冒险的一种设置,因为在这种设置下可以允许一些非法操作,比如可以将NULL插 ...

  9. boost锁的使用

    boost锁的概述 boost库中提供了mutex类与lock类,通过组合可以轻易的构建读写锁与互斥锁. ▲     mutex对象类 mutex类提供互斥量,主要有两种:boost::mutex,b ...

  10. eclipse shortcut binding

    有些真的是太方便了,我竟然不知道,比如ctrl + h 就是打开search 功能,包括file search,我竟然每次都点击工具条上的放大镜图标! use Ctrl+Shift+T for ope ...