Can anyone help me with "Rising temperature" problem in database mysql?


  • 0
    L

    The problem is:
    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) | Date(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 |
    +----+
    

    My solution is:

    select a.Id
    from Weather as a, (select *, (Id+1) as Id2 from Weather) as b
    where a.Id=b.Id2 and a.Temperature > b.Temperature
    

    It's not accepted. I can't figure out why. Can anyone shed some lights on this?

    THANK YOU!


  • 0
    S

    The ID's are not necessarily sequential. They are in the example but the SQL should not rely on that.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.