Skip to content

Commit e4eed9c

Browse files
authored
add leetcode
1 parent 3663a66 commit e4eed9c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Database/182. Duplicate Emails.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Write a SQL query to find all duplicate emails in a table named `Person`.
2+
3+
```
4+
+----+---------+
5+
| Id | Email |
6+
+----+---------+
7+
| 1 | a@b.com |
8+
| 2 | c@d.com |
9+
| 3 | a@b.com |
10+
+----+---------+
11+
```
12+
For example, your query should return the following for the above table:
13+
```
14+
+---------+
15+
| Email |
16+
+---------+
17+
| a@b.com |
18+
+---------+
19+
```
20+
Note: All emails are in lowercase.
21+
22+
**SQL**
23+
```
24+
# Write your MySQL query statement below
25+
select email from Person
26+
group by Email having count(*)>1
27+
```

Database/197. Rising Temperature.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Given a `Weather` table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.
2+
3+
```
4+
+---------+------------+------------------+
5+
| Id(INT) | Date(DATE) | Temperature(INT) |
6+
+---------+------------+------------------+
7+
| 1 | 2015-01-01 | 10 |
8+
| 2 | 2015-01-02 | 25 |
9+
| 3 | 2015-01-03 | 20 |
10+
| 4 | 2015-01-04 | 30 |
11+
+---------+------------+------------------+
12+
```
13+
For example, return the following Ids for the above Weather table:
14+
15+
```
16+
+----+
17+
| Id |
18+
+----+
19+
| 2 |
20+
| 4 |
21+
+----+
22+
```
23+
**SQL**
24+
```
25+
# Write your MySQL query statement below
26+
SELECT wt1.Id
27+
FROM Weather wt1,Weather wt2
28+
WHERE TO_DAYS(wt1.DATE)-TO_DAYS(wt2.DATE)=1
29+
&& wt1.Temperature>wt2.Temperature;
30+
```

0 commit comments

Comments
 (0)