Rising Temperature


  • 0

    Click here to see the full article post


  • 0
    D

    work in SQL Server
    select id
    from (select *, lag(temperature) over(order by date) as ptemp
    from Weather) a
    where Temperature > ptemp


  • 0
    S

    My work is Different:

    select now.Id as Id
    from Weather as previous,Weather as now
    where DATEDIFF(now.Date,previous.Date) = 1
    and now.Temperature > previous.Temperature


  • 1
    Z

    How about this simple way:
    select W1.Id from Weather as W1,Weather as W2
    where W1.Date-1=W2.Date and W1.Temperature>W2.Temperature;


  • 0
    B

    DATEDIFF(weather.date, w.date) = 1
    What if the date you checked is the next day, not yesterday? Will datediff return negative value?


  • 0
    G

    Write your MySQL query statement below

    select w2.Id
    from Weather w1, Weather w2
    where w2.Temperature > w1.Temperature and DATEDIFF(w2.Date, w1.Date) = 1
    order by 1;


  • 0
    N

    @Zhangdajun said in Rising Temperature:

    How about this simple way:
    select W1.Id from Weather as W1,Weather as W2
    where W1.Date-1=W2.Date and W1.Temperature>W2.Temperature;

    It can't be submitted successfully! So what's difference between "where t1.date – 1 = t2.date" and "DATEDIFF(t1.date,t2.tate)=1" ?


  • 0
    L

    Bingo

    select w1.id from
    Weather w1,Weather w2
    where
    DateDiff(w1.Date,w2.Date)=1
    and
    w1.Temperature>w2.Temperature;


  • 0
    D

    I don't know how to quote here @neverlate-leetcode...the problem with +1 or -1 is the dates get ruined. In this case 1900-01-01 then -1 becomes 1900-01-00...+1 on 31st becomes 32nd too. You can use @Zhangdajun's idea by using DATE_ADD:
    select a.id Id
    from Weather a
    inner join Weather b on b.date=date_add(a.date,interval -1 day)
    and a.temperature > b.temperature


Log in to reply
 

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