当前位置:网站首页>【每日SQL打卡】DAY 21丨报告系统状态的连续日期【难度困难】
【每日SQL打卡】DAY 21丨报告系统状态的连续日期【难度困难】
2022-07-29 11:43:00 【不吃西红柿】
难度困难
SQL架构
Table: Failed
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| fail_date | date |
+--------------+---------+
该表主键为 fail_date。
该表包含失败任务的天数.
Table: Succeeded
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| success_date | date |
+--------------+---------+
该表主键为 success_date。
该表包含成功任务的天数.
系统 每天 运行一个任务。每个任务都独立于先前的任务。任务的状态可以是失败或是成功。
编写一个 SQL 查询 2019-01-01 到 2019-12-31 期间任务连续同状态 period_state
的起止日期(start_date
和 end_date
)。即如果任务失败了,就是失败状态的起止日期,如果任务成功了,就是成功状态的起止日期。
最后结果按照起始日期 start_date
排序
查询结果样例如下所示:
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 |
+--------------+--------------+--------------+
| succeeded | 2019-01-01 | 2019-01-03 |
| failed | 2019-01-04 | 2019-01-05 |
| succeeded | 2019-01-06 | 2019-01-06 |
+--------------+--------------+--------------+
结果忽略了 2018 年的记录,因为我们只关心从 2019-01-01 到 2019-12-31 的记录
从 2019-01-01 到 2019-01-03 所有任务成功,系统状态为 "succeeded"。
从 2019-01-04 到 2019-01-05 所有任务失败,系统状态为 "failed"。
从 2019-01-06 到 2019-01-06 所有任务成功,系统状态为 "succeeded"。
边栏推荐
- 【每日SQL打卡】DAY 25丨不同性别每日分数总计【难度中等】
- 【Untitled】
- 如何对SQuAD1.1数据集进行预处理「详解版」
- 通过递归的方式实现树形结构
- 报表查询字段集sql摘记
- Applied practical skills of deep reinforcement learning
- 【表达式计算】表达式计算问题的通用解法(练习加强版,含总结)
- From scratch Blazor Server (3) - add cookie authorization
- How to start writing helm charts for your kubernetes application
- 【Unity3D】角色控制器(CharacterController)
猜你喜欢
Peking University open classes are coming! Welcome to the "AI for science" class
puzzle(017.5)联动归位
如何开始为您的 Kubernetes 应用程序编写 Helm 图表
如何使用 grep 跨多行查找模式匹配
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
谷歌“消灭” Cookie 计划延至 2024 年
Learning with Recoverable Forgetting readings
一次node文件操作过多排查过程总结
面试官培训课件(非常实用的企业内训课件)
Meituan and hungry were interviewed by Hangzhou supervisors to implement the responsibility of food safety management and prohibit malicious competition
随机推荐
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
IPv6 Foundation
1.4、栈
黑马四小时入门学习记录-2|本地应用
Dawei gbase8s cursor stability read esql test case
学习周刊-总第64期-一个v2ex风格的开源论坛程序
大伟 Golang之路
MyCat中间件高可用、读写分离、分片、主从切换、ER分片
TCP and UDP
Proficient in audio and video development can really do whatever you want
Great golang Road
WPF 实现平移控件
XSS漏洞分析
INVALID_ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
Self collection online computer wallpaper PHP source code v2.0 adaptive end
IPV6基础
考完PMP后有什么益处
INVALID_ ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
LMO·3rd - 报名通知
Lucky draw system with background source code