Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
SQL Schema
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.
The query result format is in the following example.
Example 1:
Input:
Weather table:
+----+------------+-------------+
| id | recordDate | temperature |
+----+------------+-------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+----+------------+-------------+
Output:
+----+
| id |
+----+
| 2 |
| 4 |
+----+
Explanation:
In 2015-01-02, the temperature was higher than the previous day (10 -> 25).
In 2015-01-04, the temperature was higher than the previous day (20 -> 30).
SELECT a.Id FROM Weather AS a, Weather AS b
WHERE DATEDIFF(a.Date, b.Date)=1 AND a.Temperature > b.Temperature
SELECT w2.Id
FROM Weather w1
INNER JOIN Weather w2 ON DATEDIFF(day, w1.recordDate, w2.recordDate)=1 AND w2.Temperature > w1.Temperature
select t.id as ID
from (select w.id,
-- w.recorddate,
w.temperature as tt,
-- lag(w.recorddate, 1) over(order by w.recorddate) as dt,
w.recorddate - lag(w.recorddate, 1) over(order by w.recorddate) as dtmin,
lag(w.temperature, 1) over(order by w.recorddate) as tmp
from weather w) t
where dtmin = 1
and t.tt > t.tmp
In our experience, we suggest you solve this Rising Temperature LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Rising Temperature LeetCode Solution
I hope this Rising Temperature LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>