zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1225. 报告系统状态的连续日期 | Report Contiguous Dates

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    SQL架构:

     1 Create table If Not Exists Failed (fail_date date)
     2 Create table If Not Exists Succeeded (success_date date)
     3 Truncate table Failed
     4 insert into Failed (fail_date) values ('2018-12-28')
     5 insert into Failed (fail_date) values ('2018-12-29')
     6 insert into Failed (fail_date) values ('2019-01-04')
     7 insert into Failed (fail_date) values ('2019-01-05')
     8 Truncate table Succeeded
     9 insert into Succeeded (success_date) values ('2018-12-30')
    10 insert into Succeeded (success_date) values ('2018-12-31')
    11 insert into Succeeded (success_date) values ('2019-01-01')
    12 insert into Succeeded (success_date) values ('2019-01-02')
    13 insert into Succeeded (success_date) values ('2019-01-03')
    14 insert into Succeeded (success_date) values ('2019-01-06')

    Table: Failed

    +--------------+---------+
    | Column Name | Type |
    +--------------+---------+
    | fail_date | date |
    +--------------+---------+
    Primary key for this table is fail_date.
    Failed table contains the days of failed tasks.
    Table: Succeeded

    +--------------+---------+
    | Column Name | Type |
    +--------------+---------+
    | success_date | date |
    +--------------+---------+
    Primary key for this table is success_date.
    Succeeded table contains the days of succeeded tasks.
     

    A system is running one task every day. Every task is independent of the previous tasks. The tasks can fail or succeed.

    Write an SQL query to generate a report of period_state for each continuous interval of days in the period from 2019-01-01 to 2019-12-31.

    period_state is 'failed' if tasks in this interval failed or 'succeeded' if tasks in this interval succeeded. Interval of days are retrieved as start_date and end_date.

    Order result by start_date.

    The query result format is in the following example:

    Failed table:
    +-------------------+
    | fail_date |
    +-------------------+
    | 2018-12-28 |
    | 2018-12-29 |
    | 2019-01-04 |
    | 2019-01-05 |
    +-------------------+

    Succeeded table:
    +-------------------+
    | success_date |
    +-------------------+
    | 2018-12-30 |
    | 2018-12-31 |
    | 2019-01-01 |
    | 2019-01-02 |
    | 2019-01-03 |
    | 2019-01-06 |
    +-------------------+


    Result table:
    +--------------+--------------+--------------+
    | period_state | start date | end date |
    +--------------+--------------+--------------+
    | present | 2019-01-01 | 2019-01-03 |
    | missing | 2019-01-04 | 2019-01-05 |
    | present | 2019-01-06 | 2019-01-06 |
    +--------------+--------------+--------------+

    The report ignored the system state in 2018 as we care about the system in the period 2019-01-01 to 2019-12-31.
    From 2019-01-01 to 2019-01-03 all tasks succeeded and the system state was "present".
    From 2019-01-04 to 2019-01-05 all tasks failed and system state was "missing".
    From 2019-01-06 to 2019-01-06 all tasks succeeded and system state was "present".

  • 相关阅读:
    构造注入
    关于事件
    泛型的一些补充
    [转]汇编语言之寄存器使用(bx,si,di,bp)
    asp.net计算页面执行时间
    运行 组件服务器 dcomcnfg
    Craig's Utility Library
    MASM内部数据类型 from: Intel汇编语言程序(第四版).djvu
    Python interpreter clear console screen
    C大小写转换问题
  • 原文地址:https://www.cnblogs.com/strengthen/p/11712796.html
Copyright © 2011-2022 走看看