Skip to content

Commit 3968814

Browse files
refactor 1285
1 parent a799f2b commit 3968814

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

database/_1285.sql

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,3 @@
1-
--1285. Find the Start and End Number of Continuous Ranges
2-
--
3-
--Table: Logs
4-
--
5-
--+---------------+---------+
6-
--| Column Name | Type |
7-
--+---------------+---------+
8-
--| log_id | int |
9-
--+---------------+---------+
10-
--id is the primary key for this table.
11-
--Each row of this table contains the ID in a log Table.
12-
--
13-
--Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs.
14-
--
15-
--Order the result table by start_id.
16-
--
17-
--The query result format is in the following example:
18-
--
19-
--Logs table:
20-
--+------------+
21-
--| log_id |
22-
--+------------+
23-
--| 1 |
24-
--| 2 |
25-
--| 3 |
26-
--| 7 |
27-
--| 8 |
28-
--| 10 |
29-
--+------------+
30-
--
31-
--Result table:
32-
--+------------+--------------+
33-
--| start_id | end_id |
34-
--+------------+--------------+
35-
--| 1 | 3 |
36-
--| 7 | 8 |
37-
--| 10 | 10 |
38-
--+------------+--------------+
39-
--The result table should contain all ranges in table Logs.
40-
--From 1 to 3 is contained in the table.
41-
--From 4 to 6 is missing in the table
42-
--From 7 to 8 is contained in the table.
43-
--Number 9 is missing in the table.
44-
--Number 10 is contained in the table.
45-
--
46-
--# Write your MySQL query statement below
471
select l1.log_id as start_id, min(l2.log_id) as end_id
482
from
493
(

0 commit comments

Comments
 (0)