Leetcode:duplicate Emails-Recurring Email

Source: Internet
Author: User
Tags mysql command line

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.