日誌2024-10-31 23:28
【Leetcode】197. Rising Temperature作者:Chris
Weather表格屬性 | |
Column Name | Type |
id | int |
recordDate | date |
temperature | int |
Weather | ||
id | recordDate | temperature |
1 | 2015-01-01 | 10 |
2 | 2015-01-02 | 25 |
3 | 2015-01-03 | 20 |
4 | 2015-01-04 | 30 |
id |
2 |
4 |
個人理解 |
前面遇到的Join語法都是兩個表格合一,這個看來是做交叉連接,有些解答甚至連join語法不會用到。但基於理解、練習join語法的情況下,目前選擇使用下列方式。 而本次習題先整合表格的資料,讓系統列出後再用datediff()來處理兩個時間的間隔、後一天比前一天溫度高的狀態來輸出成結果。 |
程式碼 |
select w2.id from Weather w1 join Weather w2 on datediff(w2.recordDate, w1.recordDate) = 1 and w2.temperature > w1.temperature; |
或 |
select today.id from Weather yesterday cross join Weather today where datediff(today.recordDate,yesterday.recordDate)=1 and today.temperature>yesterday.temperature; |