https://leetcode.com/problems/rising-temperature/
Rising Temperature - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
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 t.id AS id
FROM Weather t
INNER JOIN Weather y on t.recordDate = DATE_ADD(y.recordDate, INTERVAL 1 DAY)
WHERE t.temperature > y.temperature
SELECT *
FROM Weather t
INNER JOIN Weather y on t.recordDate = DATE_ADD(y.recordDate, INTERVAL 1 DAY)
["id", "recordDate", "temperature", "id", "recordDate", "temperature"]
[2, "2015-01-02", 25, 1, "2015-01-01", 10]
[3, "2015-01-03", 20, 2, "2015-01-02", 25]
[4, "2015-01-04", 30, 3, "2015-01-03", 20]
Duplicate Emails(LeetCode) (0) | 2022.07.30 |
---|---|
Symmetric Pairs(HackerRank) (0) | 2022.07.20 |
Employees Earning More Than Their Managers(LeetCode) (0) | 2022.07.20 |
Customers Who Never Order(LeetCode) (0) | 2022.07.20 |
Reformat Department Table(LeetCode) (0) | 2022.07.20 |
댓글 영역