Skip to content

Commit b713c3d

Browse files
committed
feat: add solutions to lc problems: No.0262,0569,0618
* No.0262.Trips and Users * No.0569.Median Employee Salary * No.0618.Students Report By Geography
1 parent 97103cc commit b713c3d

File tree

9 files changed

+185
-8
lines changed

9 files changed

+185
-8
lines changed

solution/0200-0299/0262.Trips and Users/README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,26 @@ Users 表:
128128

129129
### **SQL**
130130

131-
```
132-
131+
```sql
132+
# Write your MySQL query statement below
133+
select
134+
request_at Day,
135+
round(avg(status != 'completed'), 2) 'Cancellation Rate'
136+
from
137+
Trips t
138+
join Users u1 on (
139+
t.client_id = u1.users_id
140+
and u1.banned = 'No'
141+
)
142+
join Users u2 on (
143+
t.driver_id = u2.users_id
144+
and u2.banned = 'No'
145+
)
146+
where
147+
request_at between '2013-10-01'
148+
and '2013-10-03'
149+
group by
150+
request_at
133151
```
134152

135153
<!-- tabs:end -->

solution/0200-0299/0262.Trips and Users/README_EN.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,26 @@ On 2013-10-03:
114114

115115
### **SQL**
116116

117-
```
118-
117+
```sql
118+
# Write your MySQL query statement below
119+
select
120+
request_at Day,
121+
round(avg(status != 'completed'), 2) 'Cancellation Rate'
122+
from
123+
Trips t
124+
join Users u1 on (
125+
t.client_id = u1.users_id
126+
and u1.banned = 'No'
127+
)
128+
join Users u2 on (
129+
t.driver_id = u2.users_id
130+
and u2.banned = 'No'
131+
)
132+
where
133+
request_at between '2013-10-01'
134+
and '2013-10-03'
135+
group by
136+
request_at
119137
```
120138

121139
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Write your MySQL query statement below
2+
select
3+
request_at Day,
4+
round(avg(status != 'completed'), 2) 'Cancellation Rate'
5+
from
6+
Trips t
7+
join Users u1 on (
8+
t.client_id = u1.users_id
9+
and u1.banned = 'No'
10+
)
11+
join Users u2 on (
12+
t.driver_id = u2.users_id
13+
and u2.banned = 'No'
14+
)
15+
where
16+
request_at between '2013-10-01'
17+
and '2013-10-03'
18+
group by
19+
request_at

solution/0500-0599/0569.Median Employee Salary/README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,28 @@ Employee 表:
8181
### **SQL**
8282

8383
```sql
84-
84+
# Write your MySQL query statement below
85+
with t as (
86+
select
87+
*,
88+
row_number() over(
89+
partition by company
90+
order by
91+
salary asc
92+
) rk,
93+
count(id) over(partition by company) n
94+
from
95+
Employee
96+
)
97+
select
98+
id,
99+
company,
100+
salary
101+
from
102+
t
103+
where
104+
rk >= n / 2
105+
and rk <= n / 2 + 1;
85106
```
86107

87108
<!-- tabs:end -->

solution/0500-0599/0569.Median Employee Salary/README_EN.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,28 @@ For company C, the rows sorted are as follows:
108108
### **SQL**
109109

110110
```sql
111-
111+
# Write your MySQL query statement below
112+
with t as (
113+
select
114+
*,
115+
row_number() over(
116+
partition by company
117+
order by
118+
salary asc
119+
) rk,
120+
count(id) over(partition by company) n
121+
from
122+
Employee
123+
)
124+
select
125+
id,
126+
company,
127+
salary
128+
from
129+
t
130+
where
131+
rk >= n / 2
132+
and rk <= n / 2 + 1;
112133
```
113134

114135
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
*,
5+
row_number() over(
6+
partition by company
7+
order by
8+
salary asc
9+
) rk,
10+
count(id) over(partition by company) n
11+
from
12+
Employee
13+
)
14+
select
15+
id,
16+
company,
17+
salary
18+
from
19+
t
20+
where
21+
rk >= n / 2
22+
and rk <= n / 2 + 1;

solution/0600-0699/0618.Students Report By Geography/README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,26 @@ Student table:
6565
### **SQL**
6666

6767
```sql
68-
68+
# Write your MySQL query statement below
69+
with t as (
70+
select
71+
*,
72+
row_number() over(
73+
partition by continent
74+
order by
75+
name
76+
) rn
77+
from
78+
Student
79+
)
80+
select
81+
max(if(continent = 'America', name, null)) America,
82+
max(if(continent = 'Asia', name, null)) Asia,
83+
max(if(continent = 'Europe', name, null)) Europe
84+
from
85+
t
86+
group by
87+
rn
6988
```
7089

7190
<!-- tabs:end -->

solution/0600-0699/0618.Students Report By Geography/README_EN.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,26 @@ Student table:
6060
### **SQL**
6161

6262
```sql
63-
63+
# Write your MySQL query statement below
64+
with t as (
65+
select
66+
*,
67+
row_number() over(
68+
partition by continent
69+
order by
70+
name
71+
) rn
72+
from
73+
Student
74+
)
75+
select
76+
max(if(continent = 'America', name, null)) America,
77+
max(if(continent = 'Asia', name, null)) Asia,
78+
max(if(continent = 'Europe', name, null)) Europe
79+
from
80+
t
81+
group by
82+
rn
6483
```
6584

6685
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
*,
5+
row_number() over(
6+
partition by continent
7+
order by
8+
name
9+
) rn
10+
from
11+
Student
12+
)
13+
select
14+
max(if(continent = 'America', name, null)) America,
15+
max(if(continent = 'Asia', name, null)) Asia,
16+
max(if(continent = 'Europe', name, null)) Europe
17+
from
18+
t
19+
group by
20+
rn

0 commit comments

Comments
 (0)