Skip to content

Commit 0a9f26e

Browse files
authored
feat: add sql parser (doocs#2186)
1 parent 08f389e commit 0a9f26e

File tree

8 files changed

+13
-64
lines changed

8 files changed

+13
-64
lines changed

.prettierignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ node_modules/
1515
/solution/bash_problem_readme_template_en.md
1616
/solution/0100-0199/0177.Nth Highest Salary/Solution.sql
1717
/solution/1400-1499/1454.Active Users/Solution.sql
18-
/solution/1400-1499/1484.Group Sold Products By The Date/Solution.sql
19-
/solution/1600-1699/1613.Find the Missing IDs/Solution.sql
2018
/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql
21-
/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql
22-
/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql
2319
/solution/2100-2199/2118.Build the Equation/Solution.sql
24-
/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql
20+
/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql
2521
/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql
22+
/solution/2200-2299/2230.The Users That Are Eligible for Discount/Solution.sql
2623
/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql
2724
/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql

.prettierrc

+2-42
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,8 @@
1313
"sqlKeywordCase": "upper",
1414
"overrides": [
1515
{
16-
"files": [
17-
"solution/0100-0199/0180.Consecutive Numbers/Solution.sql",
18-
"solution/0500-0599/0550.Game Play Analysis IV/Solution.sql",
19-
"solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql",
20-
"solution/0600-0699/0610.Triangle Judgement/Solution.sql",
21-
"solution/0600-0699/0618.Students Report By Geography/Solution.sql",
22-
"solution/0600-0699/0626.Exchange Seats/Solution.sql",
23-
"solution/0600-0699/0627.Swap Salary/Solution.sql",
24-
"solution/1000-1099/1097.Game Play Analysis V/Solution.sql",
25-
"solution/1000-1099/1098.Unpopular Books/Solution.sql",
26-
"solution/1100-1199/1113.Reported Posts/Solution.sql",
27-
"solution/1100-1199/1127.User Purchase Platform/Solution.sql",
28-
"solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql",
29-
"solution/1100-1199/1193.Monthly Transactions I/Solution.sql",
30-
"solution/1200-1299/1205.Monthly Transactions II/Solution.sql",
31-
"solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql",
32-
"solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql",
33-
"solution/1300-1399/1322.Ads Performance/Solution.sql",
34-
"solution/1300-1399/1393.Capital GainLoss/Solution.sql",
35-
"solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql",
36-
"solution/1400-1499/1445.Apples & Oranges/Solution.sql",
37-
"solution/1400-1499/1479.Sales by Day of the Week/Solution.sql",
38-
"solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql",
39-
"solution/1500-1599/1511.Customer Order Frequency/Solution.sql",
40-
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
41-
"solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql",
42-
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
43-
"solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql",
44-
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
45-
"solution/1900-1999/1934.Confirmation Rate/Solution.sql",
46-
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
47-
"solution/2000-2099/2066.Account Balance/Solution.sql",
48-
"solution/2200-2299/2230.The Users That Are Eligible for Discount/Solution.sql",
49-
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
50-
"solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql",
51-
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql",
52-
"solution/2700-2799/2793.Status of Flight Tickets/Solution.sql",
53-
"solution/2900-2999/2994.Friday Purchases II/Solution.sql"
54-
],
55-
"options": {
56-
"parser": "bigquery"
57-
}
16+
"files": ["*.sql"],
17+
"options": { "parser": "mysql" }
5818
}
5919
]
6020
}

solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ WITH
33
T AS (
44
SELECT
55
log_id,
6-
log_id-ROW_NUMBER() OVER (ORDER BY log_id) AS pid
6+
log_id - ROW_NUMBER() OVER (ORDER BY log_id) AS pid
77
FROM Logs
88
)
99
SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
SELECT
22
sell_date,
33
COUNT(DISTINCT product) AS num_sold,
4-
GROUP_CONCAT(DISTINCT product
5-
ORDER BY product) AS products
6-
FROM
7-
Activities
4+
GROUP_CONCAT(DISTINCT product ORDER BY product) AS products
5+
FROM Activities
86
GROUP BY sell_date
97
ORDER BY sell_date;

solution/1600-1699/1613.Find the Missing IDs/Solution.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WHERE
1818
MAX(customer_id)
1919
FROM Customers
2020
)
21-
AND n NOT IN(
21+
AND n NOT IN (
2222
SELECT
2323
customer_id
2424
FROM Customers

solution/1600-1699/1651.Hopper Company Queries III/Solution.sql

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ WITH RECURSIVE
1414
SUM(IFNULL(ride_duration, 0)) AS ride_duration
1515
FROM
1616
Months AS m
17-
LEFT JOIN Rides AS r
18-
ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020
17+
LEFT JOIN Rides AS r ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020
1918
LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id
2019
GROUP BY month
2120
)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Write your MySQL query statement below
22
SELECT
33
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
4+
IF(employee_id % 2 = 0 OR LEFT(name, 1) = 'M', 0, salary) AS bonus
5+
FROM employees
126
ORDER BY 1;

solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ WITH
1010
SELECT bus_id, arrival_time AS dt, capacity AS cnt FROM Buses
1111
UNION ALL
1212
SELECT -1, arrival_time AS dt, -1 FROM Passengers
13-
) AS a JOIN (SELECT @t := 0 x) AS b
13+
) AS a
14+
JOIN (SELECT @t := 0 AS x) AS b
1415
)
1516
SELECT
1617
bus_id,

0 commit comments

Comments
 (0)