|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/maximum-equal-frequency "Maximum Equal Frequency") |
| 9 | + |
| 10 | +Next > |
| 11 | + |
| 12 | +## [1225. Report Contiguous Dates (Hard)](https://leetcode.com/problems/report-contiguous-dates "") |
| 13 | + |
| 14 | +<p>Table: <code>Failed</code></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | ++--------------+---------+ |
| 18 | +| Column Name | Type | |
| 19 | ++--------------+---------+ |
| 20 | +| fail_date | date | |
| 21 | ++--------------+---------+ |
| 22 | +Primary key for this table is fail_date. |
| 23 | +Failed table contains the days of failed tasks. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p>Table: <code>Succeeded</code></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | ++--------------+---------+ |
| 30 | +| Column Name | Type | |
| 31 | ++--------------+---------+ |
| 32 | +| success_date | date | |
| 33 | ++--------------+---------+ |
| 34 | +Primary key for this table is success_date. |
| 35 | +Succeeded table contains the days of succeeded tasks. |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | + |
| 40 | +<p>A system is running one task <strong>every day</strong>. Every task is independent of the previous tasks. The tasks can fail or succeed.</p> |
| 41 | + |
| 42 | +<p>Write an SQL query to generate a report of <code>period_state</code> for each continuous interval of days in the period from <strong>2019-01-01</strong> to <strong>2019-12-31</strong>.</p> |
| 43 | + |
| 44 | +<p><code>period_state</code> is <em>'failed' </em>if tasks in this interval failed or <em>'succeeded'</em> if tasks in this interval succeeded. Interval of days are retrieved as <code>start_date</code> and <code>end_date.</code></p> |
| 45 | + |
| 46 | +<p>Order result by <code>start_date</code>.</p> |
| 47 | + |
| 48 | +<p>The query result format is in the following example:</p> |
| 49 | + |
| 50 | +<pre> |
| 51 | +Failed table: |
| 52 | ++-------------------+ |
| 53 | +| fail_date | |
| 54 | ++-------------------+ |
| 55 | +| 2018-12-28 | |
| 56 | +| 2018-12-29 | |
| 57 | +| 2019-01-04 | |
| 58 | +| 2019-01-05 | |
| 59 | ++-------------------+ |
| 60 | + |
| 61 | +Succeeded table: |
| 62 | ++-------------------+ |
| 63 | +| success_date | |
| 64 | ++-------------------+ |
| 65 | +| 2018-12-30 | |
| 66 | +| 2018-12-31 | |
| 67 | +| 2019-01-01 | |
| 68 | +| 2019-01-02 | |
| 69 | +| 2019-01-03 | |
| 70 | +| 2019-01-06 | |
| 71 | ++-------------------+ |
| 72 | + |
| 73 | + |
| 74 | +Result table: |
| 75 | ++--------------+--------------+--------------+ |
| 76 | +| period_state | start date | end date | |
| 77 | ++--------------+--------------+--------------+ |
| 78 | +| present | 2019-01-01 | 2019-01-03 | |
| 79 | +| missing | 2019-01-04 | 2019-01-05 | |
| 80 | +| present | 2019-01-06 | 2019-01-06 | |
| 81 | ++--------------+--------------+--------------+ |
| 82 | + |
| 83 | +The report ignored the system state in 2018 as we care about the system in the period 2019-01-01 to 2019-12-31. |
| 84 | +From 2019-01-01 to 2019-01-03 all tasks succeeded and the system state was "present". |
| 85 | +From 2019-01-04 to 2019-01-05 all tasks failed and system state was "missing". |
| 86 | +From 2019-01-06 to 2019-01-06 all tasks succeeded and system state was "present". |
| 87 | +</pre> |
0 commit comments