Skip to content

Commit 1079345

Browse files
committed
feat: add sql solution to lc problem: No.1225
No.1225.Report Contiguous Dates
1 parent 9ade738 commit 1079345

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

solution/1200-1299/1225.Report Contiguous Dates/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,50 @@ Result table:
8585
### **SQL**
8686

8787
```sql
88-
88+
# Write your MySQL query statement below
89+
select
90+
state as period_state,
91+
min(dt) as start_date,
92+
max(dt) as end_date
93+
from
94+
(
95+
select
96+
*,
97+
subdate(
98+
dt,
99+
rank() over(
100+
partition by state
101+
order by
102+
dt
103+
)
104+
) as dif
105+
from
106+
(
107+
select
108+
'failed' as state,
109+
fail_date as dt
110+
from
111+
failed
112+
where
113+
fail_date between '2019-01-01'
114+
and '2019-12-31'
115+
union
116+
all
117+
select
118+
'succeeded' as state,
119+
success_date as dt
120+
from
121+
succeeded
122+
where
123+
success_date between '2019-01-01'
124+
and '2019-12-31'
125+
) t1
126+
) t2
127+
group by
128+
state,
129+
dif
130+
order by
131+
dt
89132
```
90133

91134
<!-- tabs:end -->

solution/1200-1299/1225.Report Contiguous Dates/README_EN.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,50 @@ From 2019-01-06 to 2019-01-06 all tasks succeeded and the system state was &quot
8989
### **SQL**
9090

9191
```sql
92-
92+
# Write your MySQL query statement below
93+
select
94+
state as period_state,
95+
min(dt) as start_date,
96+
max(dt) as end_date
97+
from
98+
(
99+
select
100+
*,
101+
subdate(
102+
dt,
103+
rank() over(
104+
partition by state
105+
order by
106+
dt
107+
)
108+
) as dif
109+
from
110+
(
111+
select
112+
'failed' as state,
113+
fail_date as dt
114+
from
115+
failed
116+
where
117+
fail_date between '2019-01-01'
118+
and '2019-12-31'
119+
union
120+
all
121+
select
122+
'succeeded' as state,
123+
success_date as dt
124+
from
125+
succeeded
126+
where
127+
success_date between '2019-01-01'
128+
and '2019-12-31'
129+
) t1
130+
) t2
131+
group by
132+
state,
133+
dif
134+
order by
135+
dt
93136
```
94137

95138
<!-- tabs:end -->
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Write your MySQL query statement below
2+
select
3+
state as period_state,
4+
min(dt) as start_date,
5+
max(dt) as end_date
6+
from
7+
(
8+
select
9+
*,
10+
subdate(
11+
dt,
12+
rank() over(
13+
partition by state
14+
order by
15+
dt
16+
)
17+
) as dif
18+
from
19+
(
20+
select
21+
'failed' as state,
22+
fail_date as dt
23+
from
24+
failed
25+
where
26+
fail_date between '2019-01-01'
27+
and '2019-12-31'
28+
union
29+
all
30+
select
31+
'succeeded' as state,
32+
success_date as dt
33+
from
34+
succeeded
35+
where
36+
success_date between '2019-01-01'
37+
and '2019-12-31'
38+
) t1
39+
) t2
40+
group by
41+
state,
42+
dif
43+
order by
44+
dt

0 commit comments

Comments
 (0)