Leetcode 182. Duplicate Emails
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的更多相关文章
- leetcode 182. Duplicate Emails having的用法 SQL执行顺序
https://leetcode.com/problems/duplicate-emails/description/ 首先sql的执行顺序是 from-->where-->group b ...
- LeetCode 182. Duplicate Emails (查找重复的电子邮箱)
题目标签: 题目给了我们一个 email 的table,让我们找到重复的 email. 可以建立 Person a, Person b, 找到两个表格中,emai 相等 但是 id 不同的 email ...
- [LeetCode] Delete Duplicate Emails 删除重复邮箱
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- [LeetCode] 182. Duplicate Emails_Easy tag: SQL
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- 【SQL】182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- 182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- LeetCode - Delete Duplicate Emails
Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping ...
- LeetCode——Delete Duplicate Emails(巧用mysql临时表)
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- [LeetCode] Duplicate Emails 重复的邮箱
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
随机推荐
- 2015年4月29日 dayofweek
#include <stdio.h>#include <stdlib.h>int DayofYear(int year, int month, int day);#define ...
- byte 读写文件
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import ja ...
- 阅读android项目源码
版权声明:欢迎转载,转载请注明出处;http://blog.csdn.net/angcyo 上一篇,我们成功导入并运行了 贝壳单词 项目. 这篇文章, 带大家一起读一读源码. 打开 贝壳单词 项目,定 ...
- JavaScript数组函数unshift、shift、pop、push使用实例
如何声明数组 s中数组的声明可以有几种方式声明 复制代码代码如下: var tmp = []; // 简写模式var tmp = new Array(); // 直接new一个var tmp = A ...
- Linux查看文件夹大小du
du命令参数详解见: http://baike.baidu.com/view/43913.htm 下面我们只对其做简单介绍: 查看linux文件目录的大小和文件夹包含的文件数 统计总数大小 d ...
- php-fpm配置优化
PHP配置文件php-fpm的优化 2013/06/28 php, php-fpm 应用加速与性能调优 评论 6,029 本文所涉及的配置文件名为PHP-fpm.conf,里面比较重要的配置项有如 ...
- UIApplication,UIWindow,UIViewController,UIView(layer)
转载自:http://www.cnblogs.com/iCocos/p/4684749.html UIApplication,UIWindow,UIViewController,UIView(laye ...
- Android App监听软键盘按键的三种方式(转)
最近有类似需求,在csdn上刚好发现,粘贴过来,以防止忘记喽 前言: 我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“G ...
- PHP :Call to undefined function mysql_connect()
今天配置apache ,php,mysql 的时候,一直报(Call to undefined function mysql_connect()),PHP一直连接不上数据库,从网上查,答案也都是千篇一 ...
- php正则表达式手册
(http://deerchao.net/tutorials/regex/regex.htm)转载:作者:deerchao php的正则表达式很强大,学好了的确有很大的用处,但是正则表达式的规则很繁琐 ...