Skip to content

Commit 59fedcb

Browse files
authored
feat: add sql solution to lc problem: No.2752 (doocs#1084)
No.2752.Customers with Maximum Number of Transactions on Consecutive Days
1 parent 3191cf3 commit 59fedcb

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
3030
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
3131
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
32-
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql"
32+
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
33+
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql"
3334
],
3435
"options": {
3536
"parser": "bigquery"

solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,29 @@ In total, the highest number of consecutive transactions is 3, achieved by custo
7171
<!-- 这里可写当前语言的特殊实现逻辑 -->
7272

7373
```sql
74-
74+
# Write your MySQL query statement below
75+
WITH
76+
s AS (
77+
SELECT
78+
customer_id,
79+
date_sub(
80+
transaction_date,
81+
INTERVAL row_number() OVER (
82+
PARTITION BY customer_id
83+
ORDER BY transaction_date
84+
) DAY
85+
) AS transaction_date
86+
FROM Transactions
87+
),
88+
t AS (
89+
SELECT customer_id, transaction_date, count(1) AS cnt
90+
FROM s
91+
GROUP BY 1, 2
92+
)
93+
SELECT customer_id
94+
FROM t
95+
WHERE cnt = (SELECT max(cnt) FROM t)
96+
ORDER BY customer_id;
7597
```
7698

7799
<!-- tabs:end -->

solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,29 @@ In total, the highest number of consecutive transactions is 3, achieved by custo
6565
### **SQL**
6666

6767
```sql
68-
68+
# Write your MySQL query statement below
69+
WITH
70+
s AS (
71+
SELECT
72+
customer_id,
73+
date_sub(
74+
transaction_date,
75+
INTERVAL row_number() OVER (
76+
PARTITION BY customer_id
77+
ORDER BY transaction_date
78+
) DAY
79+
) AS transaction_date
80+
FROM Transactions
81+
),
82+
t AS (
83+
SELECT customer_id, transaction_date, count(1) AS cnt
84+
FROM s
85+
GROUP BY 1, 2
86+
)
87+
SELECT customer_id
88+
FROM t
89+
WHERE cnt = (SELECT max(cnt) FROM t)
90+
ORDER BY customer_id;
6991
```
7092

7193
<!-- tabs:end -->
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
s AS (
4+
SELECT
5+
customer_id,
6+
date_sub(
7+
transaction_date,
8+
INTERVAL row_number() OVER (
9+
PARTITION BY customer_id
10+
ORDER BY transaction_date
11+
) DAY
12+
) AS transaction_date
13+
FROM Transactions
14+
),
15+
t AS (
16+
SELECT customer_id, transaction_date, count(1) AS cnt
17+
FROM s
18+
GROUP BY 1, 2
19+
)
20+
SELECT customer_id
21+
FROM t
22+
WHERE cnt = (SELECT max(cnt) FROM t)
23+
ORDER BY customer_id;

0 commit comments

Comments
 (0)