-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path197.rising-temperature.sql
49 lines (46 loc) · 1.38 KB
/
197.rising-temperature.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--
-- @lc app=leetcode id=197 lang=mysql
--
-- [197] Rising Temperature
--
-- https://leetcode.com/problems/rising-temperature/description/
--
-- database
-- Easy (38.05%)
-- Likes: 405
-- Dislikes: 195
-- Total Accepted: 120.5K
-- Total Submissions: 313.1K
-- Testcase Example: '{"headers": {"Weather": ["Id", "RecordDate", "Temperature"]}, "rows": {"Weather": [[1, "2015-01-01", 10], [2, "2015-01-02", 25], [3, "2015-01-03", 20], [4, "2015-01-04", 30]]}}'
--
-- Given a Weather table, write a SQL query to find all dates' Ids with higher
-- temperature compared to its previous (yesterday's) dates.
--
--
-- +---------+------------------+------------------+
-- | Id(INT) | RecordDate(DATE) | Temperature(INT) |
-- +---------+------------------+------------------+
-- | 1 | 2015-01-01 | 10 |
-- | 2 | 2015-01-02 | 25 |
-- | 3 | 2015-01-03 | 20 |
-- | 4 | 2015-01-04 | 30 |
-- +---------+------------------+------------------+
--
--
-- For example, return the following Ids for the above Weather table:
--
--
-- +----+
-- | Id |
-- +----+
-- | 2 |
-- | 4 |
-- +----+
--
--
--
-- @lc code=start
-- Write your MySQL query statement below
SELECT w1.Id AS Id
FROM Weather w1 JOIN Weather w2 on DATEDIFF(w1.RecordDate, w2.RecordDate) = 1 AND w1.Temperature > w2.Temperature
-- @lc code=end