Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfd80c4

Browse files
feat: update sql solutions to lc problems: No.0183,1821,1873 (#1779)
* No.0183.Customers Who Never Order * No.1821.Find Customers With Positive Revenue this Year * No.1873.Calculate Special Bonus
1 parent ccae5f3 commit bfd80c4

File tree

8 files changed

+43
-63
lines changed

8 files changed

+43
-63
lines changed

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ node_modules/
2121
/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql
2222
/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql
2323
/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/Solution.sql
24+
/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql
2425
/solution/2100-2199/2118.Build the Equation/Solution.sql
2526
/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql
2627
/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql

‎solution/0100-0199/0183.Customers Who Never Order/README_EN.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ Orders table:
7373

7474
## Solutions
7575

76+
**Solution 1: NOT IN**
77+
78+
List all customer IDs of existing orders, and use `NOT IN` to find customers who are not in the list.
79+
80+
**Solution 2: LEFT JOIN**
81+
82+
Use `LEFT JOIN` to join the tables and return the data where `CustomerId` is `NULL`.
83+
7684
<!-- tabs:start -->
7785

7886
### **SQL**

‎solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ Customers
6565

6666
<!-- 这里可写通用的实现逻辑 -->
6767

68+
**方法一:WHERE 子句**
69+
70+
我们可以直接使用 `WHERE` 子句来筛选出 `year``2021``revenue` 大于 0ドル$ 的客户。
71+
6872
<!-- tabs:start -->
6973

7074
### **SQL**

‎solution/1800-1899/1821.Find Customers With Positive Revenue this Year/README_EN.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ Thus only customers 1 and 4 have positive revenue in the year 2021.
6161

6262
## Solutions
6363

64+
**Solution 1: WHERE Clause**
65+
66+
We can directly use the `WHERE` clause to filter out the customers whose `year` is `2021` and `revenue` is greater than 0ドル$.
67+
6468
<!-- tabs:start -->
6569

6670
### **SQL**

‎solution/1800-1899/1873.Calculate Special Bonus/README.md‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,18 @@ Employees 表:
6363

6464
<!-- 这里可写通用的实现逻辑 -->
6565

66+
**方法一:IF 语句 + ORDER BY 子句**
67+
68+
我们可以使用 `IF` 语句来判断奖金的计算方式,然后使用 `ORDER BY` 将结果按照 `employee_id` 排序。
69+
6670
<!-- tabs:start -->
6771

6872
### **SQL**
6973

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

7276
```sql
73-
SELECT
74-
employee_id,
75-
CASE
76-
WHEN employee_id % 2 = 0
77-
OR LEFT(name, 1) = 'M' THEN 0
78-
ELSE salary
79-
END AS bonus
80-
FROM
81-
employees;
82-
```
83-
84-
MySQL
85-
86-
```sql
77+
# Write your MySQL query statement below
8778
SELECT
8879
employee_id,
8980
IF(
@@ -93,19 +84,8 @@ SELECT
9384
salary
9485
) AS bonus
9586
FROM
96-
employees;
97-
```
98-
99-
```sql
100-
# Write your MySQL query statement below
101-
SELECT
102-
employee_id,
103-
CASE
104-
WHEN (employee_id % 2 = 1 AND NAME NOT LIKE "M%") THEN salary
105-
ELSE 0
106-
END AS bonus
107-
FROM Employees
108-
ORDER BY employee_id;
87+
employees
88+
ORDER BY 1;
10989
```
11090

11191
<!-- tabs:end -->

‎solution/1800-1899/1873.Calculate Special Bonus/README_EN.md‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,16 @@ The rest of the employees get a 100% bonus.
5959

6060
## Solutions
6161

62-
<!-- tabs:start -->
62+
**Solution 1: IF Statement + ORDER BY Clause**
6363

64-
### **SQL**
64+
We can use the `IF` statement to determine the calculation method of the bonus, and then use `ORDER BY` to sort the results by `employee_id`.
6565

66-
```sql
67-
SELECT
68-
employee_id,
69-
CASE
70-
WHEN employee_id % 2 = 0
71-
OR LEFT(name, 1) = 'M' THEN 0
72-
ELSE salary
73-
END AS bonus
74-
FROM
75-
employees;
76-
```
66+
<!-- tabs:start -->
7767

78-
MySQL
68+
### **SQL**
7969

8070
```sql
71+
# Write your MySQL query statement below
8172
SELECT
8273
employee_id,
8374
IF(
@@ -87,19 +78,8 @@ SELECT
8778
salary
8879
) AS bonus
8980
FROM
90-
employees;
91-
```
92-
93-
```sql
94-
# Write your MySQL query statement below
95-
SELECT
96-
employee_id,
97-
CASE
98-
WHEN (employee_id % 2 = 1 AND NAME NOT LIKE "M%") THEN salary
99-
ELSE 0
100-
END AS bonus
101-
FROM Employees
102-
ORDER BY employee_id;
81+
employees
82+
ORDER BY 1;
10383
```
10484

10585
<!-- tabs:end -->

‎solution/1800-1899/1873.Calculate Special Bonus/Solution.SQL‎

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
employee_id,
4+
IF(
5+
employee_id % 2 = 0
6+
OR LEFT(name, 1) = 'M',
7+
0,
8+
salary
9+
) AS bonus
10+
FROM
11+
employees
12+
ORDER BY 1;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /