leetcode 182. Duplicate Emails

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 182. Duplicate Emails相关的知识,希望对你有一定的参考价值。

传送门

182. Duplicate Emails

My Submissions
Total Accepted: 14498 Total Submissions: 38364 Difficulty: Easy

 

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

+----+---------+
| Id | Email   |
+----+---------+
| 1  | [email protected] |
| 2  | [email protected] |
| 3  | [email protected] |
+----+---------+

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

+---------+
| Email   |
+---------+
| [email protected] |
+---------+

Note: All emails are in lowercase.

 

Subscribe to see which companies asked this question

 

1 # Write your mysql query statement below
2 select distinct p1.Email from 
3     Person p1,Person p2 
4         where p1.Email=p2.Email 
5             and p1.Id!=p2.Id

 

 

about distinct

 

SQL SELECT DISTINCT 语句

本章讲解 SELECT DISTINCT 语句。

SQL SELECT DISTINCT 语句

在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。

关键词 DISTINCT 用于返回唯一不同的值。

语法:

SELECT DISTINCT 列名称 FROM 表名称

使用 DISTINCT 关键词

如果要从 "Company" 列中选取所有的值,我们需要使用 SELECT 语句:

SELECT Company FROM Orders

"Orders"表:

CompanyOrderNumber
IBM 3532
3wschool 2356
Apple 4698
3wschool 6953

结果:

Company
IBM
3wschool
Apple
3wschool

请注意,在结果集中,3wschool 被列出了两次。

如需从 Company" 列中仅选取唯一不同的值,我们需要使用 SELECT DISTINCT 语句:

SELECT DISTINCT Company FROM Orders 

结果:

Company
IBM
3wschool
Apple

现在,在结果集中,"3wschool" 仅被列出了一次。

以上是关于leetcode 182. Duplicate Emails的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] 182. Duplicate Emails_Easy tag: SQL

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

LeetCode-Algorithms #007 Reverse Integer, Database #182 Duplicate Emails

LeetCode:182.查找重复的电子邮箱

182. 查找重复的电子邮箱

LeetCode-SQL-182-查找重复的电子邮箱