Skip to content

Commit c5dbbb6

Browse files
authored
feat: add sql formatter (doocs#1039)
1 parent 1f66d36 commit c5dbbb6

File tree

373 files changed

+3650
-4208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

373 files changed

+3650
-4208
lines changed

.prettierignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ node_modules/
1212
/solution/problem_readme_template.md
1313
/solution/problem_readme_template_en.md
1414
/solution/bash_problem_readme_template.md
15-
/solution/bash_problem_readme_template_en.md
15+
/solution/bash_problem_readme_template_en.md
16+
/solution/0100-0199/0177.Nth Highest Salary/Solution.sql
17+
/solution/1000-1099/1076.Project Employees II/Solution.sql
18+
/solution/1000-1099/1082.Sales Analysis I/Solution.sql
19+
/solution/1500-1599/1511.Customer Order Frequency
20+
/solution/1700-1799/1767.Find the Subtasks That Did Not Execute/Solution.sql
21+
/solution/1600-1699/1613.Find the Missing IDs/Solution.sql
22+
/solution/1400-1499/1484.Group Sold Products By The Date/Solution.sql
23+
/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql

.prettierrc

+25-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,29 @@
88
"arrowParens": "avoid",
99
"phpVersion": "8.1",
1010
"braceStyle": "1tbs",
11-
"endOfLine": "lf"
11+
"endOfLine": "lf",
12+
"sqlKeywordCase": "upper",
13+
"overrides": [
14+
{
15+
"files": [
16+
"solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql",
17+
"solution/0600-0699/0618.Students Report By Geography/Solution.sql",
18+
"solution/0600-0699/0626.Exchange Seats/Solution.sql",
19+
"solution/1000-1099/1098.Unpopular Books/Solution.sql",
20+
"solution/1100-1199/1113.Reported Posts/Solution.sql",
21+
"solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql",
22+
"solution/1100-1199/1193.Monthly Transactions I/Solution.sql",
23+
"solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql",
24+
"solution/1300-1399/1322.Ads Performance/Solution.sql",
25+
"solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql",
26+
"solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql",
27+
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
28+
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
29+
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql"
30+
],
31+
"options": {
32+
"parser": "bigquery"
33+
}
34+
}
35+
]
1236
}

package-lock.json

+34-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"clang-format": "1.8.0",
1515
"husky": "^8.0.3",
1616
"lint-staged": "^13.2.2",
17-
"prettier": "^2.8.8"
17+
"prettier": "^2.8.8",
18+
"prettier-plugin-sql-cst": "^0.8.2"
1819
},
1920
"lint-staged": {
20-
"*.{js,ts,php,md}": "prettier --write",
21+
"*.{js,ts,php,md,sql}": "prettier --write",
2122
"*.py": "black -S"
2223
}
2324
}

solution/0100-0199/0175.Combine Two Tables/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ addressId = 1 包含了 personId = 2 的地址信息。</pre>
8686

8787
```sql
8888
# Write your MySQL query statement below
89-
select
89+
SELECT
9090
firstName,
9191
lastName,
9292
city,
9393
state
94-
from
95-
Person p
96-
left join Address a on p.personId = a.personId
94+
FROM
95+
Person AS p
96+
LEFT JOIN Address AS a ON p.personId = a.personId;
9797
```
9898

9999
<!-- tabs:end -->

solution/0100-0199/0175.Combine Two Tables/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ addressId = 1 contains information about the address of personId = 2.
8282

8383
```sql
8484
# Write your MySQL query statement below
85-
select
85+
SELECT
8686
firstName,
8787
lastName,
8888
city,
8989
state
90-
from
91-
Person p
92-
left join Address a on p.personId = a.personId
90+
FROM
91+
Person AS p
92+
LEFT JOIN Address AS a ON p.personId = a.personId;
9393
```
9494

9595
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Write your MySQL query statement below
2-
select
2+
SELECT
33
firstName,
44
lastName,
55
city,
66
state
7-
from
8-
Person p
9-
left join Address a on p.personId = a.personId
7+
FROM
8+
Person AS p
9+
LEFT JOIN Address AS a ON p.personId = a.personId;

solution/0100-0199/0176.Second Highest Salary/README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ Employee 表:
8282
```sql
8383
# Write your MySQL query statement below
8484
SELECT
85-
(
86-
SELECT DISTINCT Salary
87-
FROM Employee
88-
ORDER BY Salary DESC
89-
LIMIT 1 OFFSET 1
90-
) AS SecondHighestSalary;
85+
(
86+
SELECT DISTINCT Salary
87+
FROM Employee
88+
ORDER BY Salary DESC
89+
LIMIT 1 OFFSET 1
90+
) AS SecondHighestSalary;
9191
```
9292

9393
解法 2:使用 `MAX()` 函数,从小于 `MAX()` 的 Salary 中挑选最大值 `MAX()` 即可。
@@ -96,10 +96,11 @@ SELECT
9696
# Write your MySQL query statement below
9797
SELECT MAX(Salary) AS SecondHighestSalary
9898
FROM Employee
99-
WHERE Salary < (
100-
SELECT MAX(Salary)
101-
FROM Employee
102-
);
99+
WHERE
100+
Salary < (
101+
SELECT MAX(Salary)
102+
FROM Employee
103+
);
103104
```
104105

105106
<!-- tabs:end -->

solution/0100-0199/0176.Second Highest Salary/README_EN.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ Solution 1: Use Sub Query and LIMIT.
7373
```sql
7474
# Write your MySQL query statement below
7575
SELECT
76-
(
77-
SELECT DISTINCT Salary
78-
FROM Employee
79-
ORDER BY Salary DESC
80-
LIMIT 1 OFFSET 1
81-
) AS SecondHighestSalary;
76+
(
77+
SELECT DISTINCT Salary
78+
FROM Employee
79+
ORDER BY Salary DESC
80+
LIMIT 1 OFFSET 1
81+
) AS SecondHighestSalary;
8282
```
8383

8484
Solution 2: Use `MAX()` function.
@@ -87,10 +87,11 @@ Solution 2: Use `MAX()` function.
8787
# Write your MySQL query statement below
8888
SELECT MAX(Salary) AS SecondHighestSalary
8989
FROM Employee
90-
WHERE Salary < (
91-
SELECT MAX(Salary)
92-
FROM Employee
93-
);
90+
WHERE
91+
Salary < (
92+
SELECT MAX(Salary)
93+
FROM Employee
94+
);
9495
```
9596

9697
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Write your MySQL query statement below
22
SELECT
3-
(
4-
SELECT DISTINCT Salary
5-
FROM Employee
6-
ORDER BY Salary DESC
7-
LIMIT 1 OFFSET 1
8-
) AS SecondHighestSalary;
3+
(
4+
SELECT DISTINCT Salary
5+
FROM Employee
6+
ORDER BY Salary DESC
7+
LIMIT 1 OFFSET 1
8+
) AS SecondHighestSalary;

solution/0100-0199/0178.Rank Scores/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,8 @@ DENSE_RANK() OVER (
9292
# Write your MySQL query statement below
9393
SELECT
9494
Score,
95-
DENSE_RANK() OVER (
96-
ORDER BY
97-
Score DESC
98-
) 'Rank'
99-
FROM
100-
Scores;
95+
DENSE_RANK() OVER (ORDER BY Score DESC) AS 'Rank'
96+
FROM Scores;
10197
```
10298

10399
### **MySQL5**

solution/0100-0199/0178.Rank Scores/README_EN.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ Solution:
8181
# Write your MySQL query statement below
8282
SELECT
8383
Score,
84-
DENSE_RANK() OVER (
85-
ORDER BY
86-
Score DESC
87-
) 'Rank'
88-
FROM
89-
Scores;
84+
DENSE_RANK() OVER (ORDER BY Score DESC) AS 'Rank'
85+
FROM Scores;
9086
```
9187

9288
### **MySQL5**
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# Write your MySQL query statement below
22
SELECT
33
Score,
4-
DENSE_RANK() OVER (
5-
ORDER BY
6-
Score DESC
7-
) 'Rank'
8-
FROM
9-
Scores;
4+
DENSE_RANK() OVER (ORDER BY Score DESC) AS 'Rank'
5+
FROM Scores;

solution/0100-0199/0180.Consecutive Numbers/README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ Result 表:
6161
### **SQL**
6262

6363
```sql
64-
select distinct(Num) as ConsecutiveNums from Logs Curr where
65-
Num = (select Num from Logs where id = Curr.id - 1) and
66-
Num = (select Num from Logs where id = Curr.id - 2)
64+
SELECT DISTINCT (Num) AS ConsecutiveNums
65+
FROM Logs AS Curr
66+
WHERE
67+
Num = (SELECT Num FROM Logs WHERE id = Curr.id - 1)
68+
AND Num = (SELECT Num FROM Logs WHERE id = Curr.id - 2);
6769
```
6870

6971
```sql
@@ -75,12 +77,9 @@ FROM
7577
logs AS l3
7678
WHERE
7779
l1.id = l2.id - 1
78-
AND
79-
l2.id = l3.id - 1
80-
AND
81-
l1.num = l2.num
82-
AND
83-
l2.num = l3.num
80+
AND l2.id = l3.id - 1
81+
AND l1.num = l2.num
82+
AND l2.num = l3.num;
8483
```
8584

8685
<!-- tabs:end -->

solution/0100-0199/0180.Consecutive Numbers/README_EN.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ Logs table:
5858
### **SQL**
5959

6060
```sql
61-
select distinct(Num) as ConsecutiveNums from Logs Curr where
62-
Num = (select Num from Logs where id = Curr.id - 1) and
63-
Num = (select Num from Logs where id = Curr.id - 2)
61+
SELECT DISTINCT (Num) AS ConsecutiveNums
62+
FROM Logs AS Curr
63+
WHERE
64+
Num = (SELECT Num FROM Logs WHERE id = Curr.id - 1)
65+
AND Num = (SELECT Num FROM Logs WHERE id = Curr.id - 2);
6466
```
6567

6668
```sql
@@ -72,12 +74,9 @@ FROM
7274
logs AS l3
7375
WHERE
7476
l1.id = l2.id - 1
75-
AND
76-
l2.id = l3.id - 1
77-
AND
78-
l1.num = l2.num
79-
AND
80-
l2.num = l3.num
77+
AND l2.id = l3.id - 1
78+
AND l1.num = l2.num
79+
AND l2.num = l3.num;
8180
```
8281

8382
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
select distinct(Num) as ConsecutiveNums from Logs Curr where
2-
Num = (select Num from Logs where id = Curr.id - 1) and
3-
Num = (select Num from Logs where id = Curr.id - 2)
1+
SELECT DISTINCT (Num) AS ConsecutiveNums
2+
FROM Logs AS Curr
3+
WHERE
4+
Num = (SELECT Num FROM Logs WHERE id = Curr.id - 1)
5+
AND Num = (SELECT Num FROM Logs WHERE id = Curr.id - 2);

0 commit comments

Comments
 (0)