Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
select w1.id from weather w1 ,weather w2 where datediff(w1.recordDate,w2.recordDate) = 1 and w1.temperature > w2.temperature;
EXPLAIN
select w1.id from weather w1 ,weather w2 where datediff(w1.recordDate,w2.recordDate)=1 AND w1.temperature > w2.temperature;
Thanks bro , for the simplest explanation .
Oracle Solution (Using Join)Select a.idfrom weather a join weather bon a.recordDate-b.recordDate=1 and a.temperature > b.temperature;
It worked. but 13/14 test cases passed, so it showing up as wrong answer.
appreciate your work bro please continue this awesome work
select distinct a.id from weather a join weather bon a.temperature>b.temperatureand a.recorddate
This is much easier select b.id from weather a , weather b where a.temparature< b.temparature and a.recordDate+1=b.recordDate;
doesnt work, it will fail on test cases where the dates are at month end or year end
Can we use self join here?
yes, we can use self join here.
Amazing!
Can anyone explain
WITH CTE AS(select id, temperature, lag(temperature, 1) over( order by id ) as prev_tempfrom weather)SELECT CTE.id FROM CTE WHERE temperature > cte.prev_temp ;What's wrong with this?
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.
Did using self join select w1.idfrom weather w1left join weather w2on w1.recordDate= w2.recordDate+1 where (w1.temperature-w2.temperature) > 0;
select w1.id from weather w1 ,weather w2
where datediff(w1.recordDate,w2.recordDate) = 1
and w1.temperature > w2.temperature;
EXPLAIN
select w1.id from weather w1 ,weather w2 where datediff(w1.recordDate,w2.recordDate)=1
AND w1.temperature > w2.temperature;
Thanks bro , for the simplest explanation .
Oracle Solution (Using Join)
Select a.id
from weather a join weather b
on a.recordDate-b.recordDate=1
and a.temperature > b.temperature;
It worked. but 13/14 test cases passed, so it showing up as wrong answer.
appreciate your work bro please continue this awesome work
select distinct a.id from weather a join weather b
on
a.temperature>b.temperature
and a.recorddate
This is much easier
select b.id from weather a , weather b where a.temparature< b.temparature and a.recordDate+1=b.recordDate;
doesnt work, it will fail on test cases where the dates are at month end or year end
Can we use self join here?
yes, we can use self join here.
Amazing!
Can anyone explain
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?
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.
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
;