leetcode刷题笔记一百九十六题 && 一百九十七题

leetcode刷题笔记一百九十六题 && 一百九十七题

源地址:

196. 删除重复的电子邮箱

197. 上升的温度

196问题描述:

编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+----+------------------+
Id 是这个表的主键。
例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+

提示:

执行 SQL 之后,输出是整个 Person 表。
使用 delete 语句。

# Write your MySQL query statement below
DELETE p1 FROM Person p1, Person p2 WHERE p1.Email = p2.Email and p1.Id > p2.Id;

197问题描述:

SQL架构

给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。

+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
|       1 |       2015-01-01 |               10 |
|       2 |       2015-01-02 |               25 |
|       3 |       2015-01-03 |               20 |
|       4 |       2015-01-04 |               30 |
+---------+------------------+------------------+

例如,根据上述给定的 Weather 表格,返回如下 Id:

+----+
| Id |
+----+
|  2 |
|  4 |
+----+
# Write your MySQL query statement below
SELECT w1.Id FROM Weather w1 JOIN Weather w2 On (w1.Temperature > w2.Temperature) and DATEDIFF(w1.RecordDate, w2.RecordDate) = 1; 
posted @ 2020-09-17 17:53  ganshuoos  阅读(98)  评论(0编辑  收藏  举报