You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/0100-0199/0175.Combine Two Tables/README_EN.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,10 @@ addressId = 1 contains information about the address of personId = 2.
76
76
77
77
## Solutions
78
78
79
+
**Solution 1: LEFT JOIN**
80
+
81
+
We can use a left join to join the `Person` table with the `Address` table on the condition `Person.personId = Address.personId`, which will give us the first name, last name, city, and state of each person. If the address of a `personId` is not in the `Address` table, it will be reported as `null`.
Copy file name to clipboardExpand all lines: solution/0600-0699/0607.Sales Person/README_EN.md
+11-40Lines changed: 11 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,52 +111,23 @@ According to orders 3 and 4 in the Orders table, it is easy to tell that only sa
111
111
112
112
## Solutions
113
113
114
-
<!-- tabs:start -->
114
+
**Solution 1: LEFT JOIN + GROUP BY**
115
115
116
-
### **SQL**
116
+
We can use a left join to join the `SalesPerson` table with the `Orders` table on the condition of sales id, and then join the result with the `Company` table on the condition of company id. After that, we can group by `sales_id` and count the number of orders with the company name `RED`. Finally, we can filter out the salespersons who do not have any orders with the company name `RED`.
117
117
118
-
```sql
119
-
SELECT name
120
-
FROM salesperson
121
-
WHERE
122
-
sales_id NOT IN (
123
-
SELECTs.sales_id
124
-
FROM
125
-
orders AS o
126
-
INNER JOIN salesperson AS s ONo.sales_id=s.sales_id
Copy file name to clipboardExpand all lines: solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,14 @@ Enrollments table:
55
55
56
56
## Solutions
57
57
58
+
**Solution 1: RANK() OVER() Window Function**
59
+
60
+
We can use the `RANK() OVER()` window function to sort the grades of each student in descending order. If the grades are the same, we sort them in ascending order by course number, and then select the record with a rank of 1ドル$ for each student.
61
+
62
+
**Solution 2: Subquery**
63
+
64
+
We can first query the highest grade of each student, and then query the minimum course number corresponding to the highest grade of each student.
65
+
58
66
<!-- tabs:start -->
59
67
60
68
### **SQL**
@@ -77,4 +85,18 @@ WHERE rk = 1
77
85
ORDER BY student_id;
78
86
```
79
87
88
+
```sql
89
+
# Write your MySQL query statement below
90
+
SELECT student_id, min(course_id) AS course_id, grade
Copy file name to clipboardExpand all lines: solution/1400-1499/1407.Top Travellers/README_EN.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,10 @@ Donald did not have any rides, the distance traveled by him is 0.
92
92
93
93
## Solutions
94
94
95
+
**Solution 1: LEFT JOIN + GROUP BY**
96
+
97
+
We can use a left join to join the `Users` table with the `Rides` table on the condition of user id, and then group by user id to calculate the travel distance for each user. Note that if a user has no travel records, the travel distance is 0ドル$.
98
+
95
99
<!-- tabs:start -->
96
100
97
101
### **SQL**
Collapse file: solution/1600-1699/1607.Sellers With No Sales/README.md
Copy file name to clipboardExpand all lines: solution/1600-1699/1607.Sellers With No Sales/README_EN.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,19 +104,23 @@ Frank made 1 sale in 2019 but no sales in 2020.
104
104
105
105
## Solutions
106
106
107
+
**Solution 1: LEFT JOIN + GROUP BY + FILTER**
108
+
109
+
We can use a left join to join the `Seller` table with the `Orders` table on the condition `seller_id`, and then group by `seller_id` to count the number of sales for each seller in the year 2020ドル$. Finally, we can filter out the sellers with zero sales.
110
+
107
111
<!-- tabs:start -->
108
112
109
113
### **SQL**
110
114
111
115
```sql
112
116
# Write your MySQL query statement below
113
-
SELECT
114
-
seller_name
117
+
SELECT seller_name
115
118
FROM
116
-
seller AS s
117
-
LEFT JOIN orders AS o ONs.seller_id=o.seller_idAND year(sale_date) ='2020'
0 commit comments