表:customer_transactions
+------------------+---------+ | Column Name | Type | +------------------+---------+ | transaction_id | int | | customer_id | int | | transaction_date | date | | amount | decimal | | transaction_type | varchar | +------------------+---------+ transaction_id 是这张表的唯一主键。 transaction_type 可以是 “purchase” 或 “refund”。
编写一个解决方案来查找 忠实客户。如果满足下述所有条件,可以认为该客户是 忠实 客户:
3
次购买交易。30
天。20%
。返回结果表以 customer_id
升序 排序。
结果格式如下所示。
示例:
输入:
customer_transactions 表:
+----------------+-------------+------------------+--------+------------------+ | transaction_id | customer_id | transaction_date | amount | transaction_type | +----------------+-------------+------------------+--------+------------------+ | 1 | 101 | 2024-01-05 | 150.00 | purchase | | 2 | 101 | 2024-01-15 | 200.00 | purchase | | 3 | 101 | 2024-02-10 | 180.00 | purchase | | 4 | 101 | 2024-02-20 | 250.00 | purchase | | 5 | 102 | 2024-01-10 | 100.00 | purchase | | 6 | 102 | 2024-01-12 | 120.00 | purchase | | 7 | 102 | 2024-01-15 | 80.00 | refund | | 8 | 102 | 2024-01-18 | 90.00 | refund | | 9 | 102 | 2024-02-15 | 130.00 | purchase | | 10 | 103 | 2024-01-01 | 500.00 | purchase | | 11 | 103 | 2024-01-02 | 450.00 | purchase | | 12 | 103 | 2024-01-03 | 400.00 | purchase | | 13 | 104 | 2024-01-01 | 200.00 | purchase | | 14 | 104 | 2024-02-01 | 250.00 | purchase | | 15 | 104 | 2024-02-15 | 300.00 | purchase | | 16 | 104 | 2024-03-01 | 350.00 | purchase | | 17 | 104 | 2024-03-10 | 280.00 | purchase | | 18 | 104 | 2024-03-15 | 100.00 | refund | +----------------+-------------+------------------+--------+------------------+
输出:
+-------------+ | customer_id | +-------------+ | 101 | | 104 | +-------------+
解释:
结果表以 customer_id 升序排序。