Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sql parser #2186

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ node_modules/
/solution/bash_problem_readme_template_en.md
/solution/0100-0199/0177.Nth Highest Salary/Solution.sql
/solution/1400-1499/1454.Active Users/Solution.sql
/solution/1400-1499/1484.Group Sold Products By The Date/Solution.sql
/solution/1600-1699/1613.Find the Missing IDs/Solution.sql
/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql
/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql
/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql
/solution/2100-2199/2118.Build the Equation/Solution.sql
/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql
/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql
/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql
/solution/2200-2299/2230.The Users That Are Eligible for Discount/Solution.sql
/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql
/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql
44 changes: 2 additions & 42 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,8 @@
"sqlKeywordCase": "upper",
"overrides": [
{
"files": [
"solution/0100-0199/0180.Consecutive Numbers/Solution.sql",
"solution/0500-0599/0550.Game Play Analysis IV/Solution.sql",
"solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql",
"solution/0600-0699/0610.Triangle Judgement/Solution.sql",
"solution/0600-0699/0618.Students Report By Geography/Solution.sql",
"solution/0600-0699/0626.Exchange Seats/Solution.sql",
"solution/0600-0699/0627.Swap Salary/Solution.sql",
"solution/1000-1099/1097.Game Play Analysis V/Solution.sql",
"solution/1000-1099/1098.Unpopular Books/Solution.sql",
"solution/1100-1199/1113.Reported Posts/Solution.sql",
"solution/1100-1199/1127.User Purchase Platform/Solution.sql",
"solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql",
"solution/1100-1199/1193.Monthly Transactions I/Solution.sql",
"solution/1200-1299/1205.Monthly Transactions II/Solution.sql",
"solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql",
"solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql",
"solution/1300-1399/1322.Ads Performance/Solution.sql",
"solution/1300-1399/1393.Capital GainLoss/Solution.sql",
"solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql",
"solution/1400-1499/1445.Apples & Oranges/Solution.sql",
"solution/1400-1499/1479.Sales by Day of the Week/Solution.sql",
"solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql",
"solution/1500-1599/1511.Customer Order Frequency/Solution.sql",
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
"solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql",
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
"solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql",
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
"solution/1900-1999/1934.Confirmation Rate/Solution.sql",
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
"solution/2000-2099/2066.Account Balance/Solution.sql",
"solution/2200-2299/2230.The Users That Are Eligible for Discount/Solution.sql",
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
"solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql",
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql",
"solution/2700-2799/2793.Status of Flight Tickets/Solution.sql",
"solution/2900-2999/2994.Friday Purchases II/Solution.sql"
],
"options": {
"parser": "bigquery"
}
"files": ["*.sql"],
"options": { "parser": "mysql" }
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WITH
T AS (
SELECT
log_id,
log_id-ROW_NUMBER() OVER (ORDER BY log_id) AS pid
log_id - ROW_NUMBER() OVER (ORDER BY log_id) AS pid
FROM Logs
)
SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
SELECT
sell_date,
COUNT(DISTINCT product) AS num_sold,
GROUP_CONCAT(DISTINCT product
ORDER BY product) AS products
FROM
Activities
GROUP_CONCAT(DISTINCT product ORDER BY product) AS products
FROM Activities
GROUP BY sell_date
ORDER BY sell_date;
2 changes: 1 addition & 1 deletion solution/1600-1699/1613.Find the Missing IDs/Solution.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WHERE
MAX(customer_id)
FROM Customers
)
AND n NOT IN(
AND n NOT IN (
SELECT
customer_id
FROM Customers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ WITH RECURSIVE
SUM(IFNULL(ride_duration, 0)) AS ride_duration
FROM
Months AS m
LEFT JOIN Rides AS r
ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020
LEFT JOIN Rides AS r ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020
LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id
GROUP BY month
)
Expand Down
10 changes: 2 additions & 8 deletions solution/1800-1899/1873.Calculate Special Bonus/Solution.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Write your MySQL query statement below
SELECT
employee_id,
IF(
employee_id % 2 = 0
OR LEFT(name, 1) = 'M',
0,
salary
) AS bonus
FROM
employees
IF(employee_id % 2 = 0 OR LEFT(name, 1) = 'M', 0, salary) AS bonus
FROM employees
ORDER BY 1;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ WITH
SELECT bus_id, arrival_time AS dt, capacity AS cnt FROM Buses
UNION ALL
SELECT -1, arrival_time AS dt, -1 FROM Passengers
) AS a JOIN (SELECT @t := 0 x) AS b
) AS a
JOIN (SELECT @t := 0 AS x) AS b
)
SELECT
bus_id,
Expand Down