当前位置:网站首页>【每日SQL打卡】DAY 24丨找到连续区间的开始和结束数字【难度中等】
【每日SQL打卡】DAY 24丨找到连续区间的开始和结束数字【难度中等】
2022-07-29 11:42:00 【不吃西红柿】
难度中等
SQL架构
表:Logs
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| log_id | int |
+---------------+---------+
id 是上表的主键。
上表的每一行包含日志表中的一个 ID。后来一些 ID 从 Logs 表中删除。编写一个 SQL 查询得到 Logs 表中的连续区间的开始数字和结束数字。
将查询表按照 start_id 排序。
查询结果格式如下面的例子:
Logs 表:
+------------+
| log_id |
+------------+
| 1 |
| 2 |
| 3 |
| 7 |
| 8 |
| 10 |
+------------+
结果表:
+------------+--------------+
| start_id | end_id |
+------------+--------------+
| 1 | 3 |
| 7 | 8 |
| 10 | 10 |
+------------+--------------+
结果表应包含 Logs 表中的所有区间。
从 1 到 3 在表中。
从 4 到 6 不在表中。
从 7 到 8 在表中。
9 不在表中。
10 在表中。边栏推荐
- Learn weekly - 64 - a v2ex style source BBS program
- [image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
- 迁徙数据平台简单介绍
- DNS协议、ICMP协议、NAT技术
- 【Untitled】
- 如何对SQuAD1.1数据集进行预处理「详解版」
- 大伟 Golang之路
- WPF 实现平移控件
- Exclusive interview | Cheng Li, chief technology officer of Alibaba: cloud + open source together form a credible foundation for the digital world
- WeChat red envelope test case
猜你喜欢
随机推荐
c语言:来实现一个小程序n子棋(已五子棋为例)
Niuke net brush questions
mapbox 地图 生成矢量数据圆
Insights into the development of the enterprise live broadcast industry in 2022
Lucky draw system with background source code
MFC学习备忘
AI model risk assessment Part 2: core content
幸运抽奖系统带后台源码
Paddlelite compilation and code running through the disk
如何对SQuAD1.1数据集进行预处理「详解版」
通过递归的方式实现树形结构
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
【Unity3D】场景切换、退出全屏、退出游戏
Basic. Blocking
【无标题】
自采集在线电脑壁纸php源码v2.0自适应端
什么是 Kubernetes 自定义资源定义 (CRD)?
微信发红包测试用例
力扣sql刷题(四)
The interviewer training courseware (very practical in-house training courseware)








