Rising Temperature - SQL - Easy - LeetCode
💻 coding

Rising Temperature - SQL - Easy - LeetCode

1 min read 176 words
1 min read
ShareWhatsAppPost on X
  • 1The Weather table contains daily temperature records with an id as the primary key.
  • 2The SQL query identifies dates with higher temperatures than the previous day.
  • 3Results include ids of days where the temperature increased compared to the day before.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The Weather table contains daily temperature records with an id as the primary key."

Rising Temperature - SQL - Easy - LeetCode

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 in a certain day.

Write an SQL query to find all dates' id with higher temperature compared to its previous dates (yesterday).

Return the result table in any order.

The query result format is in the following example:

Weather +----+------------+-------------+ | id | recordDate | Temperature | +----+------------+-------------+ | 1 | 2015-01-01 | 10 | | 2 | 2015-01-02 | 25 | | 3 | 2015-01-03 | 20 | | 4 | 2015-01-04 | 30 | +----+------------+-------------+

Result table: +----+ | id | +----+ | 2 | | 4 | +----+ In 2015-01-02, temperature was higher than the previous day (10 -> 25). In 2015-01-04, temperature was higher than the previous day (30 -> 20).

# Write your MySQL query statement below
select w1.id from Weather w1, Weather w2 Where w1.Temperature > w2.Temperature And TO_DAYS(w1.recordDate)-TO_DAYS(w2.recordDate)=1;

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

sumitc91

Published on 16 October 2020 · 1 min read · 176 words

Part of AskGif Blog · coding

You might also like