Skip to content

Commit 8a30799

Browse files
committed
feat: add sql solutions: No.1045 & No.1050
1 parent 178632e commit 8a30799

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

solution/1000-1099/1045.Customers Who Bought All Products/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ Result 表:
7272
### **SQL**
7373

7474
```sql
75-
75+
# Write your MySQL query statement below
76+
SELECT
77+
customer_id
78+
FROM
79+
Customer
80+
GROUP BY
81+
customer_id
82+
HAVING
83+
COUNT(DISTINCT(product_key)) = (
84+
SELECT
85+
COUNT(1)
86+
FROM
87+
Product
88+
);
7689
```
7790

7891
<!-- tabs:end -->

solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,20 @@ The customers who bought all the products (5 and 6) are customers with id 1 and
7777
### **SQL**
7878

7979
```sql
80-
80+
# Write your MySQL query statement below
81+
SELECT
82+
customer_id
83+
FROM
84+
Customer
85+
GROUP BY
86+
customer_id
87+
HAVING
88+
COUNT(DISTINCT(product_key)) = (
89+
SELECT
90+
COUNT(1)
91+
FROM
92+
Product
93+
);
8194
```
8295

8396
<!-- tabs:end -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
customer_id
4+
FROM
5+
Customer
6+
GROUP BY
7+
customer_id
8+
HAVING
9+
COUNT(DISTINCT(product_key)) = (
10+
SELECT
11+
COUNT(1)
12+
FROM
13+
Product
14+
);

solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ Result 表:
5252

5353
<!-- 这里可写通用的实现逻辑 -->
5454

55+
`GROUP BY` + `HAVING` 解决。
56+
5557
<!-- tabs:start -->
5658

5759
### **SQL**
5860

5961
```sql
60-
62+
# Write your MySQL query statement below
63+
SELECT
64+
actor_id, director_id
65+
FROM
66+
ActorDirector
67+
GROUP BY actor_id, director_id
68+
HAVING count(1) >= 3;
6169
```
6270

6371
<!-- tabs:end -->

solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@ The only pair is (1, 1) where they cooperated exactly 3 times.
9090

9191
## Solutions
9292

93+
Use `GROUP BY` & `HAVING`.
94+
9395
<!-- tabs:start -->
9496

9597
### **SQL**
9698

9799
```sql
98-
100+
# Write your MySQL query statement below
101+
SELECT
102+
actor_id, director_id
103+
FROM
104+
ActorDirector
105+
GROUP BY actor_id, director_id
106+
HAVING count(1) >= 3;
99107
```
100108

101109
<!-- tabs:end -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
actor_id, director_id
4+
FROM
5+
ActorDirector
6+
GROUP BY actor_id, director_id
7+
HAVING count(1) >= 3;

0 commit comments

Comments
 (0)