当前位置: 首页 > 资讯 > 详情

LeetCode2752Customers with Maximum Number of Transactions on Con

来源:哔哩哔哩    时间:2023-08-12 09:19:51

Description

Table: Transactions


(资料图片)

+------------------+------+ 

| Column Name      | Type | 

+------------------+------+ 

| transaction_id   | int  | 

| customer_id      | int  | 

| transaction_date | date | 

| amount           | int  | 

+------------------+------+ 

transaction_id is the primary key of this row contains information about transactions that includes unique (customer_id, transaction_date) along with the corresponding customer_id and amount.  

Write an SQL query to find all customer_idwho made the maximum number of transactions on consecutive days.

Return all customer_idwith the maximum number of consecutive transactions. Order the result table by customer_idin ascending order.

The query result format is in the following example.

Example 1:

Input: 

Transactions table:

+----------------+-------------+------------------+--------+ 

| transaction_id | customer_id | transaction_date | amount | 

+----------------+-------------+------------------+--------+ 

| 1              | 101         | 2023-05-01       | 100    | 

| 2              | 101         | 2023-05-02       | 150    | 

| 3              | 101         | 2023-05-03       | 200    |

| 4              | 102         | 2023-05-01       | 50     | 

| 5              | 102         | 2023-05-03       | 100    | 

| 6              | 102         | 2023-05-04       | 200    | 

| 7              | 105         | 2023-05-01       | 100    | 

| 8              | 105         | 2023-05-02       | 150    | 

| 9              | 105         | 2023-05-03       | 200    | 

+----------------+-------------+------------------+--------+

Output: 

+-------------+ 

| customer_id |

+-------------+ 

| 101         | 

| 105         | 

+-------------+

Explanation: 

- customer_id 101 has a total of 3 transactions, and all of them are consecutive.- customer_id 102 has a total of 3 transactions, but only 2 of them are consecutive. - customer_id 105 has a total of 3 transactions, and all of them are total, the highest number of consecutive transactions is 3, achieved by customer_id 101 and 105. The customer_id are sorted in ascending order.

X 关闭

Copyright ©  2015-2023 京津冀商报网版权所有  备案号:京ICP备2022022245号-12   联系邮箱:434 922 62 @qq.com