LeetCode 197 "Rising Temperature" Amazon & Adobe Interview SQL Question with Detailed Explanation

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024

Комментарии • 17

  • @walk_with_mohan
    @walk_with_mohan 5 месяцев назад +3

    select w1.id from weather w1 ,weather w2
    where datediff(w1.recordDate,w2.recordDate) = 1
    and w1.temperature > w2.temperature;

  • @aaravkumarsingh4018
    @aaravkumarsingh4018 2 года назад +9

    select w1.id from weather w1 ,weather w2 where datediff(w1.recordDate,w2.recordDate)=1
    AND w1.temperature > w2.temperature;

    • @juveneilslife7623
      @juveneilslife7623 8 месяцев назад

      Thanks bro , for the simplest explanation .

  • @kshirod_behera
    @kshirod_behera 11 месяцев назад +3

    Oracle Solution (Using Join)
    Select a.id
    from weather a join weather b
    on a.recordDate-b.recordDate=1
    and a.temperature > b.temperature;

    • @rajatverma2776
      @rajatverma2776 7 месяцев назад

      It worked. but 13/14 test cases passed, so it showing up as wrong answer.

  • @justcodeitbro1312
    @justcodeitbro1312 3 месяца назад

    appreciate your work bro please continue this awesome work

  • @mickyman753
    @mickyman753 8 дней назад

    select distinct a.id from weather a join weather b
    on
    a.temperature>b.temperature
    and a.recorddate

  • @dileepn2479
    @dileepn2479 2 года назад +3

    This is much easier
    select b.id from weather a , weather b where a.temparature< b.temparature and a.recordDate+1=b.recordDate;

    • @TuringTested01
      @TuringTested01 Год назад

      doesnt work, it will fail on test cases where the dates are at month end or year end

  • @balamira297
    @balamira297 2 года назад +4

    Can we use self join here?

  • @neelshah8247
    @neelshah8247 Год назад

    Amazing!

  • @sindhujajittuka9020
    @sindhujajittuka9020 Год назад

    Can anyone explain

  • @abhinavtiwari6186
    @abhinavtiwari6186 7 месяцев назад

    WITH CTE AS(
    select id, temperature, lag(temperature, 1) over( order by id ) as prev_temp
    from weather
    )
    SELECT CTE.id FROM CTE WHERE temperature > cte.prev_temp ;
    What's wrong with this?

    • @hoonoh676
      @hoonoh676 7 месяцев назад

      There's no corelation between id and date; therefore, Order by should be on Date not ID, and there might be some date without any temperature data.

  • @avadhootmuli1842
    @avadhootmuli1842 3 месяца назад +1

    Did using self join
    select w1.id
    from weather w1
    left join weather w2
    on w1.recordDate= w2.recordDate+1
    where (w1.temperature-w2.temperature) > 0
    ;