Skip to content

Commit 4d91a90

Browse files
authored
Update Rising Temperature.sql
1 parent aeef687 commit 4d91a90

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

Easy/Rising Temperature.sql

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,53 @@
2121
-- Solution
2222
select a.Id
2323
from weather a, weather b
24-
where a.Temperature>b.Temperature and datediff(a.recorddate,b.recorddate)=1
24+
where a.Temperature>b.Temperature and datediff(a.recorddate,b.recorddate)=1
25+
26+
27+
28+
My sol:
29+
30+
1.
31+
with cte as (
32+
select
33+
id as id1,
34+
recordDate as rd1,
35+
temperature as t1,
36+
rd0 = lag(recordDate) over(order by id),
37+
t0 = lag(temperature) over(order by id)
38+
from Weather_12
39+
)
40+
select id1
41+
from cte
42+
where datediff(day, rd0, rd1) = 1 and t1 > t0
43+
44+
2.
45+
select a.id
46+
from Weather_12 a inner join Weather_12 b on a.temperature > b.temperature
47+
and datediff(day, b.recorddate, a.recorddate) = 1
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+

0 commit comments

Comments
 (0)