Skip to content

Commit 29a4a10

Browse files
Find Users With Valid E-Mails - TRY AGAIN
1 parent e859440 commit 29a4a10

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Leetcode_1517.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Find Users With Valid E-Mails
3+
4+
Table: Users
5+
6+
+---------------+---------+
7+
| Column Name | Type |
8+
+---------------+---------+
9+
| user_id | int |
10+
| name | varchar |
11+
| mail | varchar |
12+
+---------------+---------+
13+
user_id is the primary key for this table.
14+
This table contains information of the users signed up in a website. Some e-mails are invalid.
15+
16+
17+
Write an SQL query to find the users who have valid emails.
18+
19+
A valid e-mail has a prefix name and a domain where:
20+
21+
The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.' and/or dash '-'.
22+
The prefix name must start with a letter. The domain is '@leetcode.com'.
23+
24+
Return the result table in any order.
25+
26+
The query result format is in the following example.
27+
28+
Users
29+
+---------+-----------+-------------------------+
30+
| user_id | name | mail |
31+
+---------+-----------+-------------------------+
32+
| 1 | Winston | [email protected] |
33+
| 2 | Jonathan | jonathanisgreat |
34+
| 3 | Annabelle | [email protected] |
35+
| 4 | Sally | [email protected] |
36+
| 5 | Marwan | quarz#[email protected] |
37+
| 6 | David | [email protected] |
38+
| 7 | Shapiro | [email protected] |
39+
+---------+-----------+-------------------------+
40+
41+
Result table:
42+
+---------+-----------+-------------------------+
43+
| user_id | name | mail |
44+
+---------+-----------+-------------------------+
45+
| 1 | Winston | [email protected] |
46+
| 3 | Annabelle | [email protected] |
47+
| 4 | Sally | [email protected] |
48+
+---------+-----------+-------------------------+
49+
The mail of user 2 doesn't have a domain.
50+
The mail of user 5 has # sign which is not allowed.
51+
The mail of user 6 doesn't have leetcode domain.
52+
The mail of user 7 starts with a period.
53+
*/
54+
55+
SELECT *
56+
FROM Users
57+
WHERE mail REGEXP '^[a-zA-Z]{1}[a-zA-Z0-9_.-]*@leetcode.com$'

0 commit comments

Comments
 (0)