File tree Expand file tree Collapse file tree 3 files changed +132
-2
lines changed
solution/1200-1299/1225.Report Contiguous Dates Expand file tree Collapse file tree 3 files changed +132
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,50 @@ Result table:
85
85
### ** SQL**
86
86
87
87
``` 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
89
132
```
90
133
91
134
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -89,7 +89,50 @@ From 2019-01-06 to 2019-01-06 all tasks succeeded and the system state was "
89
89
### ** SQL**
90
90
91
91
``` 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
93
136
```
94
137
95
138
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments