1. Title
Duplicate Emails (recurring email)
2. Address of the topic
https://leetcode.com/problems/duplicate-emails/
3. Topic content
There is a data table including ID and email two column, find the data table in the e-mail column content repeated email data.
For example, the existing table person content is as follows:
+----+---------+| Id | Email |+----+---------+| 1 | [Email protected] | | 2 | [Email protected] | | 3 | [Email protected] |+----+---------+
Then the resulting set of queries is:
+---------+| Email |+---------+| [Email protected] |+---------+
4. Initializing Database Scripts
Create a database named Leetcode in the MySQL database and execute the following script with the source command in the MySQL command line:
--The Databaseuse leetcode;drop TABLE IF EXISTS person named Leetcode must be established before executing the script; CREATE TABLE person (ID int. not NULL PRIMARY KEY, e-mail VARCHAR); INSERT into person (ID, email) VALUES (1, ' [email Protected] '); INSERT into person (ID, email) VALUES (2, ' [email protected] ') and insert into person (ID, email) VALUES (3, ' [EM AIL protected] '); INSERT into person (ID, email) VALUES (4, ' [email protected] '); Insert in person (ID, email) VALUES (5, ' [email protected] ';
5, Problem solving SQL1
Group data in an email column to find all emails with more than 1 data in the group
SELECT DISTINCT emailfrom Persongroup by emailhaving COUNT (*) > 1
6, Problem solving SQL2
A different perspective, if the two rows of data, ID, email the same, then select this email, and then all the selected email to go to heavy.
SELECT DISTINCT a.emailfrom Person as A, person as bwhere a.id <> b.id and a.email = B.email
END
Leetcode:duplicate Emails-Recurring Email