조컴퓨터

leetcode 197. Rising Temperature 본문

LeetCode/SQL

leetcode 197. Rising Temperature

챠오위 2021. 1. 18. 20:02

 

 

1) SELF JOIN

 

1-1) 

SELECT *
FROM Weather w1, Weather w2
WHERE DATE_ADD(w1.recordDate, INTERVAL 1 DAY) = w2.recordDate
   AND w1.Temperature < w2.Temperature

 

1-1) 결과

{"headers": ["Id", "RecordDate", "Temperature", "Id", "RecordDate", "Temperature"],

"values": [[1, "2015-01-01", 10, 2, "2015-01-02", 25], [3, "2015-01-03", 20, 4, "2015-01-04", 30]]}

 

 

 

2) w2.Id

 

2-1)

SELECT w2.Id AS Id
FROM Weather w1, Weather w2 
WHERE DATE_ADD(w1.recordDate, INTERVAL 1 DAY) = w2.recordDate 
   AND w1.Temperature < w2.Temperature

 

2-1) 결과

{"headers": ["Id"], "values": [[2], [4]]}

 

 

SUCCESS!!

 

 

 

 

 

'LeetCode > SQL' 카테고리의 다른 글

leetcode 181. Employees Earning More Than Their Managers  (0) 2021.01.18
leetcode 1179. Reformat Department Table  (0) 2021.01.18