Skip to content

Commit f88efde

Browse files
authored
feat: add sql solutions to lc problems: No.0627,1661,1677 (#1108)
* No.0627.Swap Salary * No.1661.Average Time of Process per Machine * No.1677.Product's Worth Over Invoices
1 parent 47dc07b commit f88efde

File tree

10 files changed

+94
-9
lines changed

10 files changed

+94
-9
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ node_modules/
1414
/solution/bash_problem_readme_template.md
1515
/solution/bash_problem_readme_template_en.md
1616
/solution/0100-0199/0177.Nth Highest Salary/Solution.sql
17+
/solution/0600-0699/0627.Swap Salary/Solution.sql
1718
/solution/1000-1099/1076.Project Employees II/Solution.sql
1819
/solution/1000-1099/1082.Sales Analysis I/Solution.sql
1920
/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql

solution/0600-0699/0627.Swap Salary/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ SET sex = CASE sex
7878
END;
7979
```
8080

81+
```sql
82+
# Write your MySQL query statement below
83+
UPDATE Salary
84+
SET sex = if(sex = 'f', 'm', 'f');
85+
```
86+
8187
<!-- tabs:end -->

solution/0600-0699/0627.Swap Salary/README_EN.md

+6
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ SET sex = CASE sex
7070
END;
7171
```
7272

73+
```sql
74+
# Write your MySQL query statement below
75+
UPDATE Salary
76+
SET sex = if(sex = 'f', 'm', 'f');
77+
```
78+
7379
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
UPDATE salary
2-
SET sex = CASE sex
3-
WHEN 'm' THEN 'f'
4-
ELSE 'm'
5-
END;
1+
# Write your MySQL query statement below
2+
UPDATE Salary
3+
SET sex = if(sex = 'f', 'm', 'f');

solution/1600-1699/1661.Average Time of Process per Machine/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,20 @@ Activity table:
8484
### **SQL**
8585

8686
```sql
87-
87+
# Write your MySQL query statement below
88+
SELECT
89+
machine_id,
90+
round(
91+
avg(
92+
CASE
93+
WHEN activity_type = 'start' THEN -timestamp
94+
ELSE timestamp
95+
END
96+
) * 2,
97+
3
98+
) AS processing_time
99+
FROM Activity
100+
GROUP BY machine_id;
88101
```
89102

90103
<!-- tabs:end -->

solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,20 @@ Machine 2&#39;s average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
8080
### **SQL**
8181

8282
```sql
83-
83+
# Write your MySQL query statement below
84+
SELECT
85+
machine_id,
86+
round(
87+
avg(
88+
CASE
89+
WHEN activity_type = 'start' THEN -timestamp
90+
ELSE timestamp
91+
END
92+
) * 2,
93+
3
94+
) AS processing_time
95+
FROM Activity
96+
GROUP BY machine_id;
8497
```
8598

8699
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
machine_id,
4+
round(
5+
avg(
6+
CASE
7+
WHEN activity_type = 'start' THEN -timestamp
8+
ELSE timestamp
9+
END
10+
) * 2,
11+
3
12+
) AS processing_time
13+
FROM Activity
14+
GROUP BY machine_id;

solution/1600-1699/1677.Product's Worth Over Invoices/README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ Result 表:
9393
### **SQL**
9494

9595
```sql
96-
96+
# Write your MySQL query statement below
97+
SELECT
98+
name,
99+
ifnull(sum(rest), 0) AS rest,
100+
ifnull(sum(paid), 0) AS paid,
101+
ifnull(sum(canceled), 0) AS canceled,
102+
ifnull(sum(refunded), 0) AS refunded
103+
FROM
104+
Product
105+
LEFT JOIN Invoice USING (product_id)
106+
GROUP BY product_id
107+
ORDER BY name;
97108
```
98109

99110
<!-- tabs:end -->

solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@ Invoice table:
9696
### **SQL**
9797

9898
```sql
99-
99+
# Write your MySQL query statement below
100+
SELECT
101+
name,
102+
ifnull(sum(rest), 0) AS rest,
103+
ifnull(sum(paid), 0) AS paid,
104+
ifnull(sum(canceled), 0) AS canceled,
105+
ifnull(sum(refunded), 0) AS refunded
106+
FROM
107+
Product
108+
LEFT JOIN Invoice USING (product_id)
109+
GROUP BY product_id
110+
ORDER BY name;
100111
```
101112

102113
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
name,
4+
ifnull(sum(rest), 0) AS rest,
5+
ifnull(sum(paid), 0) AS paid,
6+
ifnull(sum(canceled), 0) AS canceled,
7+
ifnull(sum(refunded), 0) AS refunded
8+
FROM
9+
Product
10+
LEFT JOIN Invoice USING (product_id)
11+
GROUP BY product_id
12+
ORDER BY name;

0 commit comments

Comments
 (0)