题目:
Table: Weather
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| recordDate | date |
| temperature | int |
+---------------+---------+
id is the primary key for this table.
This table contains information about the temperature on a certain day.
Write an SQL query to find all dates' Id with higher temperatures compared to its previous dates (yesterday).
Return the result table in any order.
给定一个table,找出温度比前一天高的日期的id
SELECT a.id AS IdFROM Weather AS a JOIN Weather AS bON a.temperature>b.temperature and DATEDIFF(a.recordDate,b.recordDate)=1;
将该表(a表)跟另一个自己(b表)结合
条件设a表temperature大于b表的temperature且a表recordDate和b表recordDate的差为1
然后把a表的id选出就好
最后执行时间401ms(faster than 87.26%)
那我们下题见