Skip to content

feat: add sql solution to lc problem: No.2752 #1084

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

Merged
merged 1 commit into from
Jun 27, 2023
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
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql"
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql"
],
"options": {
"parser": "bigquery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,29 @@ In total, the highest number of consecutive transactions is 3, achieved by custo
<!-- 这里可写当前语言的特殊实现逻辑 -->

```sql

# Write your MySQL query statement below
WITH
s AS (
SELECT
customer_id,
date_sub(
transaction_date,
INTERVAL row_number() OVER (
PARTITION BY customer_id
ORDER BY transaction_date
) DAY
) AS transaction_date
FROM Transactions
),
t AS (
SELECT customer_id, transaction_date, count(1) AS cnt
FROM s
GROUP BY 1, 2
)
SELECT customer_id
FROM t
WHERE cnt = (SELECT max(cnt) FROM t)
ORDER BY customer_id;
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,29 @@ In total, the highest number of consecutive transactions is 3, achieved by custo
### **SQL**

```sql

# Write your MySQL query statement below
WITH
s AS (
SELECT
customer_id,
date_sub(
transaction_date,
INTERVAL row_number() OVER (
PARTITION BY customer_id
ORDER BY transaction_date
) DAY
) AS transaction_date
FROM Transactions
),
t AS (
SELECT customer_id, transaction_date, count(1) AS cnt
FROM s
GROUP BY 1, 2
)
SELECT customer_id
FROM t
WHERE cnt = (SELECT max(cnt) FROM t)
ORDER BY customer_id;
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Write your MySQL query statement below
WITH
s AS (
SELECT
customer_id,
date_sub(
transaction_date,
INTERVAL row_number() OVER (
PARTITION BY customer_id
ORDER BY transaction_date
) DAY
) AS transaction_date
FROM Transactions
),
t AS (
SELECT customer_id, transaction_date, count(1) AS cnt
FROM s
GROUP BY 1, 2
)
SELECT customer_id
FROM t
WHERE cnt = (SELECT max(cnt) FROM t)
ORDER BY customer_id;