Skip to content

Commit 521eab6

Browse files
authored
feat: add sql solutions to lc problems: No.1517,1623,1635 (doocs#1097)
* No.1517.Find Users With Valid E-Mails * No.1623.All Valid Triplets That Can Represent a Country * No.1635.Hopper Company Queries I
1 parent c553f20 commit 521eab6

File tree

10 files changed

+153
-6
lines changed

10 files changed

+153
-6
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ node_modules/
2121
/solution/1400-1499/1484.Group Sold Products By The Date/Solution.sql
2222
/solution/1500-1599/1511.Customer Order Frequency
2323
/solution/1600-1699/1613.Find the Missing IDs/Solution.sql
24+
/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql
2425
/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/Solution.sql

solution/1500-1599/1517.Find Users With Valid E-Mails/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,17 @@ user_id (用户 ID)是该表的主键。
6868

6969
<!-- 这里可写通用的实现逻辑 -->
7070

71+
**方法一:REGEXP 正则匹配**
72+
7173
<!-- tabs:start -->
7274

7375
### **SQL**
7476

7577
```sql
76-
78+
# Write your MySQL query statement below
79+
SELECT *
80+
FROM Users
81+
WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$';
7782
```
7883

7984
<!-- tabs:end -->

solution/1500-1599/1517.Find Users With Valid E-Mails/README_EN.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ The mail of user 7 starts with a period.
7272
### **SQL**
7373

7474
```sql
75-
75+
# Write your MySQL query statement below
76+
SELECT *
77+
FROM Users
78+
WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$';
7679
```
7780

7881
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Write your MySQL query statement below
2+
SELECT *
3+
FROM Users
4+
WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$';

solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,22 @@ SchoolA</code> table:
125125
### **SQL**
126126

127127
```sql
128-
128+
# Write your MySQL query statement below
129+
SELECT
130+
a.student_name AS member_A,
131+
b.student_name AS member_B,
132+
c.student_name AS member_C
133+
FROM
134+
SchoolA AS a,
135+
SchoolB AS b,
136+
SchoolC AS c
137+
WHERE
138+
a.student_name != b.student_name
139+
AND a.student_name != c.student_name
140+
AND b.student_name != c.student_name
141+
AND a.student_id != b.student_id
142+
AND a.student_id != c.student_id
143+
AND b.student_id != c.student_id;
129144
```
130145

131146
<!-- tabs:end -->

solution/1600-1699/1623.All Valid Triplets That Can Represent a Country/README_EN.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,22 @@ Let us see all the possible triplets.
117117
### **SQL**
118118

119119
```sql
120-
120+
# Write your MySQL query statement below
121+
SELECT
122+
a.student_name AS member_A,
123+
b.student_name AS member_B,
124+
c.student_name AS member_C
125+
FROM
126+
SchoolA AS a,
127+
SchoolB AS b,
128+
SchoolC AS c
129+
WHERE
130+
a.student_name != b.student_name
131+
AND a.student_name != c.student_name
132+
AND b.student_name != c.student_name
133+
AND a.student_id != b.student_id
134+
AND a.student_id != c.student_id
135+
AND b.student_id != c.student_id;
121136
```
122137

123138
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
a.student_name AS member_A,
4+
b.student_name AS member_B,
5+
c.student_name AS member_C
6+
FROM
7+
SchoolA AS a,
8+
SchoolB AS b,
9+
SchoolC AS c
10+
WHERE
11+
a.student_name != b.student_name
12+
AND a.student_name != c.student_name
13+
AND b.student_name != c.student_name
14+
AND a.student_id != b.student_id
15+
AND a.student_id != c.student_id
16+
AND b.student_id != c.student_id;

solution/1600-1699/1635.Hopper Company Queries I/README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,36 @@ ride_id是该表的主键。
161161
### **SQL**
162162

163163
```sql
164-
164+
# Write your MySQL query statement below
165+
WITH
166+
recursive Months AS (
167+
SELECT
168+
1 AS month
169+
UNION ALL
170+
SELECT
171+
month + 1
172+
FROM Months
173+
WHERE month < 12
174+
),
175+
Ride AS (
176+
SELECT month(requested_at) AS month, count(1) AS cnt
177+
FROM
178+
Rides AS r
179+
JOIN AcceptedRides AS a
180+
ON r.ride_id = a.ride_id AND year(requested_at) = 2020
181+
GROUP BY month
182+
)
183+
SELECT
184+
m.month,
185+
count(driver_id) AS active_drivers,
186+
ifnull(r.cnt, 0) AS accepted_rides
187+
FROM
188+
Months AS m
189+
LEFT JOIN Drivers AS d
190+
ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020)
191+
OR year(d.join_date) < 2020
192+
LEFT JOIN Ride AS r ON m.month = r.month
193+
GROUP BY month;
165194
```
166195

167196
<!-- tabs:end -->

solution/1600-1699/1635.Hopper Company Queries I/README_EN.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,36 @@ By the end of December --&gt; six active drivers (10, 8, 5, 7, 4, 1) and one acc
157157
### **SQL**
158158

159159
```sql
160-
160+
# Write your MySQL query statement below
161+
WITH
162+
recursive Months AS (
163+
SELECT
164+
1 AS month
165+
UNION ALL
166+
SELECT
167+
month + 1
168+
FROM Months
169+
WHERE month < 12
170+
),
171+
Ride AS (
172+
SELECT month(requested_at) AS month, count(1) AS cnt
173+
FROM
174+
Rides AS r
175+
JOIN AcceptedRides AS a
176+
ON r.ride_id = a.ride_id AND year(requested_at) = 2020
177+
GROUP BY month
178+
)
179+
SELECT
180+
m.month,
181+
count(driver_id) AS active_drivers,
182+
ifnull(r.cnt, 0) AS accepted_rides
183+
FROM
184+
Months AS m
185+
LEFT JOIN Drivers AS d
186+
ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020)
187+
OR year(d.join_date) < 2020
188+
LEFT JOIN Ride AS r ON m.month = r.month
189+
GROUP BY month;
161190
```
162191

163192
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
recursive Months AS (
4+
SELECT
5+
1 AS month
6+
UNION ALL
7+
SELECT
8+
month + 1
9+
FROM Months
10+
WHERE month < 12
11+
),
12+
Ride AS (
13+
SELECT month(requested_at) AS month, count(1) AS cnt
14+
FROM
15+
Rides AS r
16+
JOIN AcceptedRides AS a
17+
ON r.ride_id = a.ride_id AND year(requested_at) = 2020
18+
GROUP BY month
19+
)
20+
SELECT
21+
m.month,
22+
count(driver_id) AS active_drivers,
23+
ifnull(r.cnt, 0) AS accepted_rides
24+
FROM
25+
Months AS m
26+
LEFT JOIN Drivers AS d
27+
ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020)
28+
OR year(d.join_date) < 2020
29+
LEFT JOIN Ride AS r ON m.month = r.month
30+
GROUP BY month;

0 commit comments

Comments
 (0)