題目:
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 Id
FROM Weather AS a JOIN Weather AS b
ON 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%)
那我們下題見