File tree 12 files changed +78
-56
lines changed
0100-0199/0182.Duplicate Emails
1050.Actors and Directors Who Cooperated At Least Three Times
1500-1599/1587.Bank Account Summary II
12 files changed +78
-56
lines changed Original file line number Diff line number Diff line change 39
39
### ** SQL**
40
40
41
41
``` 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 ;
43
46
```
44
47
45
48
``` 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 ;
53
54
```
54
55
55
56
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -54,17 +54,18 @@ Person table:
54
54
### ** SQL**
55
55
56
56
``` 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 ;
58
61
```
59
62
60
63
``` 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 ;
68
69
```
69
70
70
71
<!-- tabs:end -->
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ Result 表:
58
58
### ** SQL**
59
59
60
60
``` sql
61
- # Write your MySQL query statement below
62
61
SELECT
63
62
actor_id, director_id
64
63
FROM
Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ Use `GROUP BY` & `HAVING`.
60
60
### ** SQL**
61
61
62
62
``` sql
63
- # Write your MySQL query statement below
64
63
SELECT
65
64
actor_id, director_id
66
65
FROM
Original file line number Diff line number Diff line change 1
- # Write your MySQL query statement below
2
1
SELECT
3
2
actor_id, director_id
4
3
FROM
Original file line number Diff line number Diff line change @@ -90,7 +90,13 @@ id 3的产品在2019年春季之后销售。
90
90
### ** SQL**
91
91
92
92
``` 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 ;
94
100
```
95
101
96
102
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -86,7 +86,13 @@ We return only product 1 as it is the product that was only sold in the spring o
86
86
### ** SQL**
87
87
88
88
``` 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 ;
90
96
```
91
97
92
98
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -85,26 +85,21 @@ Charlie 的余额为(6000 + 6000 - 4000) = 8000.
85
85
86
86
<!-- tabs:start -->
87
87
88
- ### ** Python3 **
88
+ ### ** SQL **
89
89
90
90
<!-- 这里可写当前语言的特殊实现逻辑 -->
91
91
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 ;
108
103
```
109
104
110
105
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -85,22 +85,19 @@ Charlie's balance is (6000 + 6000 - 4000) = 8000.
85
85
86
86
<!-- tabs:start -->
87
87
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 ;
104
101
```
105
102
106
103
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments