Skip to content

Commit e0bddbf

Browse files
committed
feat: add sql solution to lc problem: No.1613
No.1613.Find the Missing IDs
1 parent 3175d73 commit e0bddbf

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

solution/1600-1699/1613.Find the Missing IDs/README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,45 @@ Customers</code> 表:
5757

5858
<!-- 这里可写通用的实现逻辑 -->
5959

60+
**方法一:递归**
61+
62+
利用 `recursive` 关键字,递归生成 `[1, 100]` 的序列,然后排除已有的 `customer_id`,即可得到结果。
63+
6064
<!-- tabs:start -->
6165

6266
### **SQL**
6367

6468
```sql
65-
69+
# Write your MySQL query statement below
70+
with recursive t as (
71+
select
72+
1 as n
73+
union
74+
all
75+
select
76+
n + 1
77+
from
78+
t
79+
where
80+
n < 100
81+
)
82+
select
83+
n ids
84+
from
85+
t
86+
where
87+
n < (
88+
select
89+
max(customer_id)
90+
from
91+
Customers
92+
)
93+
and n not in (
94+
select
95+
customer_id
96+
from
97+
Customers
98+
)
6699
```
67100

68101
<!-- tabs:end -->

solution/1600-1699/1613.Find the Missing IDs/README_EN.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,36 @@ The maximum customer_id present in the table is 5, so in the range [1,5], IDs 2
5858
### **SQL**
5959

6060
```sql
61-
61+
# Write your MySQL query statement below
62+
with recursive t as (
63+
select
64+
1 as n
65+
union
66+
all
67+
select
68+
n + 1
69+
from
70+
t
71+
where
72+
n < 100
73+
)
74+
select
75+
n ids
76+
from
77+
t
78+
where
79+
n < (
80+
select
81+
max(customer_id)
82+
from
83+
Customers
84+
)
85+
and n not in (
86+
select
87+
customer_id
88+
from
89+
Customers
90+
)
6291
```
6392

6493
<!-- tabs:end -->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Write your MySQL query statement below
2+
with recursive t as (
3+
select
4+
1 as n
5+
union
6+
all
7+
select
8+
n + 1
9+
from
10+
t
11+
where
12+
n < 100
13+
)
14+
select
15+
n ids
16+
from
17+
t
18+
where
19+
n < (
20+
select
21+
max(customer_id)
22+
from
23+
Customers
24+
)
25+
and n not in (
26+
select
27+
customer_id
28+
from
29+
Customers
30+
)

0 commit comments

Comments
 (0)