Skip to content

Commit c8fdac1

Browse files
committed
feat: add sql solution to lc problems: No.0182,1050,1084,1587
- No.0182.Duplicate Emails - No.1050.Actors and Directors Who Cooperated At Least Three Times - No.1084.Sales Analysis III - No.1587.Bank Account Summary II
1 parent b6f76f1 commit c8fdac1

File tree

12 files changed

+78
-56
lines changed

12 files changed

+78
-56
lines changed

solution/0100-0199/0182.Duplicate Emails/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939
### **SQL**
4040

4141
```sql
42-
select Email from Person group by Email having count(Email) > 1
42+
SELECT Email
43+
FROM Person
44+
GROUP BY Email
45+
HAVING count(Email) > 1;
4346
```
4447

4548
```sql
46-
# Write your MySQL query statement below
47-
SELECT DISTINCT
48-
p1.email AS "Email"
49-
FROM
50-
person AS p1
51-
JOIN person AS p2 ON p1.id != p2.id
52-
AND p1.email = p2.email
49+
SELECT DISTINCT p1.email
50+
FROM person AS p1,
51+
person AS p2
52+
WHERE p1.id != p2.id
53+
AND p1.email = p2.email;
5354
```
5455

5556
<!-- tabs:end -->

solution/0100-0199/0182.Duplicate Emails/README_EN.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ Person table:
5454
### **SQL**
5555

5656
```sql
57-
select Email from Person group by Email having count(Email) > 1
57+
SELECT Email
58+
FROM Person
59+
GROUP BY Email
60+
HAVING count(Email) > 1;
5861
```
5962

6063
```sql
61-
# Write your MySQL query statement below
62-
SELECT DISTINCT
63-
p1.email AS "Email"
64-
FROM
65-
person AS p1
66-
JOIN person AS p2 ON p1.id != p2.id
67-
AND p1.email = p2.email
64+
SELECT DISTINCT p1.email
65+
FROM person AS p1,
66+
person AS p2
67+
WHERE p1.id != p2.id
68+
AND p1.email = p2.email;
6869
```
6970

7071
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
select Name as Employee from Employee Curr where
2-
Salary > (select Salary from Employee where Id = Curr.ManagerId)
1+
SELECT Email
2+
FROM Person
3+
GROUP BY Email
4+
HAVING count(Email) > 1;

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

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Result 表:
5858
### **SQL**
5959

6060
```sql
61-
# Write your MySQL query statement below
6261
SELECT
6362
actor_id, director_id
6463
FROM

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

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Use `GROUP BY` & `HAVING`.
6060
### **SQL**
6161

6262
```sql
63-
# Write your MySQL query statement below
6463
SELECT
6564
actor_id, director_id
6665
FROM

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Write your MySQL query statement below
21
SELECT
32
actor_id, director_id
43
FROM

solution/1000-1099/1084.Sales Analysis III/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ id 3的产品在2019年春季之后销售。
9090
### **SQL**
9191

9292
```sql
93-
93+
SELECT p.product_id,
94+
P.product_name
95+
FROM product AS p
96+
JOIN sales AS s ON p.product_id = s.product_id
97+
GROUP BY p.product_id
98+
HAVING SUM(sale_date < '2019-01-01') = 0
99+
AND SUM(sale_date > '2019-03-31') = 0;
94100
```
95101

96102
<!-- tabs:end -->

solution/1000-1099/1084.Sales Analysis III/README_EN.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ We return only product 1 as it is the product that was only sold in the spring o
8686
### **SQL**
8787

8888
```sql
89-
89+
SELECT p.product_id,
90+
P.product_name
91+
FROM product AS p
92+
JOIN sales AS s ON p.product_id = s.product_id
93+
GROUP BY p.product_id
94+
HAVING SUM(sale_date < '2019-01-01') = 0
95+
AND SUM(sale_date > '2019-03-31') = 0;
9096
```
9197

9298
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT p.product_id,
2+
P.product_name
3+
FROM product AS p
4+
JOIN sales AS s ON p.product_id = s.product_id
5+
GROUP BY p.product_id
6+
HAVING SUM(sale_date < '2019-01-01') = 0
7+
AND SUM(sale_date > '2019-03-31') = 0;

solution/1500-1599/1587.Bank Account Summary II/README.md

+12-17
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,21 @@ Charlie 的余额为(6000 + 6000 - 4000) = 8000.
8585

8686
<!-- tabs:start -->
8787

88-
### **Python3**
88+
### **SQL**
8989

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

92-
```python
93-
94-
```
95-
96-
### **Java**
97-
98-
<!-- 这里可写当前语言的特殊实现逻辑 -->
99-
100-
```java
101-
102-
```
103-
104-
### **...**
105-
106-
```
107-
92+
```sql
93+
SELECT
94+
u.name,
95+
SUM(t.amount) AS balance
96+
FROM
97+
users AS u
98+
JOIN transactions AS t ON u.account = t.account
99+
GROUP BY
100+
name
101+
HAVING
102+
SUM(t.amount) > 10000;
108103
```
109104

110105
<!-- tabs:end -->

solution/1500-1599/1587.Bank Account Summary II/README_EN.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,19 @@ Charlie&#39;s balance is (6000 + 6000 - 4000) = 8000.
8585

8686
<!-- tabs:start -->
8787

88-
### **Python3**
89-
90-
```python
91-
92-
```
93-
94-
### **Java**
95-
96-
```java
97-
98-
```
99-
100-
### **...**
101-
102-
```
103-
88+
### **SQL**
89+
90+
```sql
91+
SELECT
92+
u.name,
93+
SUM(t.amount) AS balance
94+
FROM
95+
users AS u
96+
JOIN transactions AS t ON u.account = t.account
97+
GROUP BY
98+
name
99+
HAVING
100+
SUM(t.amount) > 10000;
104101
```
105102

106103
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT
2+
u.name,
3+
SUM(t.amount) AS balance
4+
FROM
5+
users AS u
6+
JOIN transactions AS t ON u.account = t.account
7+
GROUP BY
8+
name
9+
HAVING
10+
SUM(t.amount) > 10000;

0 commit comments

Comments
 (0)