其他分享
首页 > 其他分享> > 20.4.25 上升的温度 简单197

20.4.25 上升的温度 简单197

作者:互联网

题目

给定一个 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 |
+----+

解题思路

  1. 主要是运用dateDiff的函数,mysql中只需要两个标准date作为参数

代码

# Write your MySQL query statement below
SELECT S.Id
FROM Weather AS T
INNER JOIN Weather AS S
ON dateDiff(S.RecordDate,T.RecordDate) = 1 
WHERE T.Temperature<S.Temperature

标签:25,01,20.4,Temperature,197,Weather,2015,RecordDate,Id
来源: https://www.cnblogs.com/wasi-991017/p/12772628.html