Skip to content

Commit 44532ca

Browse files
committedApr 9, 2022
feat: add sql solution to lc problems: No.0175,1581,1795
- No.0175.Combine Two Tables - No.1581.Customer Who Visited but Did Not Make Any Transactions - No.1795.Rearrange Products Table
1 parent 5a37944 commit 44532ca

File tree

9 files changed

+97
-47
lines changed

9 files changed

+97
-47
lines changed
 

‎solution/0100-0199/0175.Combine Two Tables/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ AddressId 是上表主键
5151
### **SQL**
5252

5353
```sql
54-
# Write your MySQL query statement below
55-
SELECT p.FirstName, p.LastName, a.City, a.State
54+
SELECT p.FirstName,
55+
p.LastName,
56+
a.City,
57+
a.State
5658
FROM Person p
57-
LEFT JOIN Address a
58-
ON p.PersonId = a.PersonId;
59+
LEFT JOIN Address a ON p.PersonId = a.PersonId;
5960
```
6061

6162
<!-- tabs:end -->

‎solution/0100-0199/0175.Combine Two Tables/README_EN.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ addressId = 1 contains information about the address of personId = 2.
8181
### **SQL**
8282

8383
```sql
84-
# Write your MySQL query statement below
85-
SELECT p.FirstName, p.LastName, a.City, a.State
84+
SELECT p.FirstName,
85+
p.LastName,
86+
a.City,
87+
a.State
8688
FROM Person p
87-
LEFT JOIN Address a
88-
ON p.PersonId = a.PersonId;
89+
LEFT JOIN Address a ON p.PersonId = a.PersonId;
8990
```
9091

9192
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Write your MySQL query statement below
2-
SELECT p.FirstName, p.LastName, a.City, a.State
1+
SELECT p.FirstName,
2+
p.LastName,
3+
a.City,
4+
a.State
35
FROM Person p
4-
LEFT JOIN Address a
5-
ON p.PersonId = a.PersonId;
6+
LEFT JOIN Address a ON p.PersonId = a.PersonId;

‎solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,19 @@ ID = 96 的顾客曾经去过购物中心,并且没有进行任何交易。
8888

8989
<!-- tabs:start -->
9090

91-
### **Python3**
91+
### **SQL**
9292

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

95-
```python
96-
97-
```
98-
99-
### **Java**
100-
101-
<!-- 这里可写当前语言的特殊实现逻辑 -->
102-
103-
```java
104-
105-
```
106-
107-
### **...**
108-
109-
```
110-
95+
```sql
96+
SELECT customer_id,
97+
COUNT(*) AS count_no_trans
98+
FROM Visits
99+
WHERE visit_id NOT IN (
100+
SELECT visit_id
101+
FROM Transactions
102+
)
103+
GROUP BY customer_id;
111104
```
112105

113106
<!-- tabs:end -->

‎solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,19 @@ As we can see, users with IDs 30 and 96 visited the mall one time without making
8989

9090
<!-- tabs:start -->
9191

92-
### **Python3**
93-
94-
```python
95-
96-
```
97-
98-
### **Java**
99-
100-
```java
101-
102-
```
103-
104-
### **...**
105-
106-
```
107-
92+
### **SQL**
93+
94+
<!-- 这里可写当前语言的特殊实现逻辑 -->
95+
96+
```sql
97+
SELECT customer_id,
98+
COUNT(*) AS count_no_trans
99+
FROM Visits
100+
WHERE visit_id NOT IN (
101+
SELECT visit_id
102+
FROM Transactions
103+
)
104+
GROUP BY customer_id;
108105
```
109106

110107
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT customer_id,
2+
COUNT(*) AS count_no_trans
3+
FROM Visits
4+
WHERE visit_id NOT IN (
5+
SELECT visit_id
6+
FROM Transactions
7+
)
8+
GROUP BY customer_id;

‎solution/1700-1799/1795.Rearrange Products Table/README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,23 @@ Products table:
6868
<!-- 这里可写当前语言的特殊实现逻辑 -->
6969

7070
```sql
71-
71+
SELECT product_id,
72+
'store1' AS store,
73+
store1 AS price
74+
FROM products
75+
WHERE store1 IS NOT NULL
76+
UNION
77+
SELECT product_id,
78+
'store2' AS store,
79+
store2 AS price
80+
FROM products
81+
WHERE store2 IS NOT NULL
82+
UNION
83+
SELECT product_id,
84+
'store3' AS store,
85+
store3 AS price
86+
FROM products
87+
WHERE store3 IS NOT NULL;
7288
```
7389

7490
<!-- tabs:end -->

‎solution/1700-1799/1795.Rearrange Products Table/README_EN.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,23 @@ Product 1 is available in store1 with price 70 and store3 with price 80. The pro
6262
### **SQL**
6363

6464
```sql
65-
65+
SELECT product_id,
66+
'store1' AS store,
67+
store1 AS price
68+
FROM products
69+
WHERE store1 IS NOT NULL
70+
UNION
71+
SELECT product_id,
72+
'store2' AS store,
73+
store2 AS price
74+
FROM products
75+
WHERE store2 IS NOT NULL
76+
UNION
77+
SELECT product_id,
78+
'store3' AS store,
79+
store3 AS price
80+
FROM products
81+
WHERE store3 IS NOT NULL;
6682
```
6783

6884
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT product_id,
2+
'store1' AS store,
3+
store1 AS price
4+
FROM products
5+
WHERE store1 IS NOT NULL
6+
UNION
7+
SELECT product_id,
8+
'store2' AS store,
9+
store2 AS price
10+
FROM products
11+
WHERE store2 IS NOT NULL
12+
UNION
13+
SELECT product_id,
14+
'store3' AS store,
15+
store3 AS price
16+
FROM products
17+
WHERE store3 IS NOT NULL;

0 commit comments

Comments
 (0)
Please sign in to comment.