Skip to content

Commit 845fbbf

Browse files
committed
feat: add sql solutions to lc problems: No.2004,2010
* No.2004.The Number of Seniors and Juniors to Join the Company * No.2010.The Number of Seniors and Juniors to Join the Company II
1 parent e0bddbf commit 845fbbf

File tree

6 files changed

+309
-4
lines changed

6 files changed

+309
-4
lines changed

solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,70 @@ Candidates table:
9292

9393
<!-- 这里可写通用的实现逻辑 -->
9494

95+
**方法一:窗口函数**
96+
97+
相似题目:
98+
99+
- [2010. 职员招聘人数 II](/solution/2000-2099/2010.The%20Number%20of%20Seniors%20and%20Juniors%20to%20Join%20the%20Company%20II/README.md)
100+
95101
<!-- tabs:start -->
96102

97103
### **SQL**
98104

99105
<!-- 这里可写当前语言的特殊实现逻辑 -->
100106

101107
```sql
102-
108+
# Write your MySQL query statement below
109+
with s as (
110+
select
111+
employee_id,
112+
sum(salary) over(
113+
order by
114+
salary
115+
) cur
116+
from
117+
Candidates
118+
where
119+
experience = 'Senior'
120+
),
121+
j as (
122+
select
123+
employee_id,
124+
ifnull(
125+
(
126+
select
127+
max(cur)
128+
from
129+
s
130+
where
131+
cur <= 70000
132+
),
133+
0
134+
) + sum(salary) over(
135+
order by
136+
salary
137+
) cur
138+
from
139+
Candidates
140+
where
141+
experience = 'Junior'
142+
)
143+
select
144+
'Senior' experience,
145+
count(employee_id) accepted_candidates
146+
from
147+
s
148+
where
149+
cur <= 70000
150+
union
151+
all
152+
select
153+
'Junior' experience,
154+
count(employee_id) accepted_candidates
155+
from
156+
j
157+
where
158+
cur <= 70000;
103159
```
104160

105161
<!-- tabs:end -->

solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,57 @@ We can hire all three juniors with the remaining budget.
9696
### **SQL**
9797

9898
```sql
99-
99+
# Write your MySQL query statement below
100+
with s as (
101+
select
102+
employee_id,
103+
sum(salary) over(
104+
order by
105+
salary
106+
) cur
107+
from
108+
Candidates
109+
where
110+
experience = 'Senior'
111+
),
112+
j as (
113+
select
114+
employee_id,
115+
ifnull(
116+
(
117+
select
118+
max(cur)
119+
from
120+
s
121+
where
122+
cur <= 70000
123+
),
124+
0
125+
) + sum(salary) over(
126+
order by
127+
salary
128+
) cur
129+
from
130+
Candidates
131+
where
132+
experience = 'Junior'
133+
)
134+
select
135+
'Senior' experience,
136+
count(employee_id) accepted_candidates
137+
from
138+
s
139+
where
140+
cur <= 70000
141+
union
142+
all
143+
select
144+
'Junior' experience,
145+
count(employee_id) accepted_candidates
146+
from
147+
j
148+
where
149+
cur <= 70000;
100150
```
101151

102152
<!-- tabs:end -->
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Write your MySQL query statement below
2+
with s as (
3+
select
4+
employee_id,
5+
sum(salary) over(
6+
order by
7+
salary
8+
) cur
9+
from
10+
Candidates
11+
where
12+
experience = 'Senior'
13+
),
14+
j as (
15+
select
16+
employee_id,
17+
ifnull(
18+
(
19+
select
20+
max(cur)
21+
from
22+
s
23+
where
24+
cur <= 70000
25+
),
26+
0
27+
) + sum(salary) over(
28+
order by
29+
salary
30+
) cur
31+
from
32+
Candidates
33+
where
34+
experience = 'Junior'
35+
)
36+
select
37+
'Senior' experience,
38+
count(employee_id) accepted_candidates
39+
from
40+
s
41+
where
42+
cur <= 70000
43+
union
44+
all
45+
select
46+
'Junior' experience,
47+
count(employee_id) accepted_candidates
48+
from
49+
j
50+
where
51+
cur <= 70000;

solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,67 @@ Candidates table:
9797

9898
<!-- 这里可写通用的实现逻辑 -->
9999

100+
**方法一:窗口函数**
101+
102+
相似题目:
103+
104+
- [2004. 职员招聘人数](/solution/2000-2099/2004.The%20Number%20of%20Seniors%20and%20Juniors%20to%20Join%20the%20Company/README.md)
105+
100106
<!-- tabs:start -->
101107

102108
### **SQL**
103109

104110
<!-- 这里可写当前语言的特殊实现逻辑 -->
105111

106112
```sql
107-
113+
# Write your MySQL query statement below
114+
with s as (
115+
select
116+
employee_id,
117+
sum(salary) over(
118+
order by
119+
salary
120+
) cur
121+
from
122+
Candidates
123+
where
124+
experience = 'Senior'
125+
),
126+
j as (
127+
select
128+
employee_id,
129+
ifnull(
130+
(
131+
select
132+
max(cur)
133+
from
134+
s
135+
where
136+
cur <= 70000
137+
),
138+
0
139+
) + sum(salary) over(
140+
order by
141+
salary
142+
) cur
143+
from
144+
Candidates
145+
where
146+
experience = 'Junior'
147+
)
148+
select
149+
employee_id
150+
from
151+
s
152+
where
153+
cur <= 70000
154+
union
155+
select
156+
employee_id
157+
from
158+
j
159+
where
160+
cur <= 70000;
108161
```
109162

110163
<!-- tabs:end -->

solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,54 @@ We can hire all three juniors with the remaining budget.
100100
### **SQL**
101101

102102
```sql
103-
103+
# Write your MySQL query statement below
104+
with s as (
105+
select
106+
employee_id,
107+
sum(salary) over(
108+
order by
109+
salary
110+
) cur
111+
from
112+
Candidates
113+
where
114+
experience = 'Senior'
115+
),
116+
j as (
117+
select
118+
employee_id,
119+
ifnull(
120+
(
121+
select
122+
max(cur)
123+
from
124+
s
125+
where
126+
cur <= 70000
127+
),
128+
0
129+
) + sum(salary) over(
130+
order by
131+
salary
132+
) cur
133+
from
134+
Candidates
135+
where
136+
experience = 'Junior'
137+
)
138+
select
139+
employee_id
140+
from
141+
s
142+
where
143+
cur <= 70000
144+
union
145+
select
146+
employee_id
147+
from
148+
j
149+
where
150+
cur <= 70000;
104151
```
105152

106153
<!-- tabs:end -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Write your MySQL query statement below
2+
with s as (
3+
select
4+
employee_id,
5+
sum(salary) over(
6+
order by
7+
salary
8+
) cur
9+
from
10+
Candidates
11+
where
12+
experience = 'Senior'
13+
),
14+
j as (
15+
select
16+
employee_id,
17+
ifnull(
18+
(
19+
select
20+
max(cur)
21+
from
22+
s
23+
where
24+
cur <= 70000
25+
),
26+
0
27+
) + sum(salary) over(
28+
order by
29+
salary
30+
) cur
31+
from
32+
Candidates
33+
where
34+
experience = 'Junior'
35+
)
36+
select
37+
employee_id
38+
from
39+
s
40+
where
41+
cur <= 70000
42+
union
43+
select
44+
employee_id
45+
from
46+
j
47+
where
48+
cur <= 70000;

0 commit comments

Comments
 (0)