mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	update
This commit is contained in:
		
							
								
								
									
										116
									
								
								leetcode-cn/problem (Chinese)/寻找忠实客户 [find-loyal-customers].html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								leetcode-cn/problem (Chinese)/寻找忠实客户 [find-loyal-customers].html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
<p>表:<code>customer_transactions</code></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
+------------------+---------+
 | 
			
		||||
| Column Name      | Type    | 
 | 
			
		||||
+------------------+---------+
 | 
			
		||||
| transaction_id   | int     |
 | 
			
		||||
| customer_id      | int     |
 | 
			
		||||
| transaction_date | date    |
 | 
			
		||||
| amount           | decimal |
 | 
			
		||||
| transaction_type | varchar |
 | 
			
		||||
+------------------+---------+
 | 
			
		||||
transaction_id 是这张表的唯一主键。
 | 
			
		||||
transaction_type 可以是 “purchase” 或 “refund”。
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p>编写一个解决方案来查找 <strong>忠实客户</strong>。如果满足下述所有条件,可以认为该客户是 <strong>忠实</strong> 客户:</p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li>进行了 <strong>至少</strong> <code><font face="monospace">3</font></code> 次购买交易。</li>
 | 
			
		||||
	<li>活跃了 <strong>至少</strong> <code>30</code> 天。</li>
 | 
			
		||||
	<li>他们的 <strong>退款率</strong> 少于 <code>20%</code>。</li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
<p>返回结果表以 <code>customer_id</code> <strong>升序</strong> 排序。</p>
 | 
			
		||||
 | 
			
		||||
<p>结果格式如下所示。</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
 | 
			
		||||
<p><strong class="example">示例:</strong></p>
 | 
			
		||||
 | 
			
		||||
<div class="example-block">
 | 
			
		||||
<p><strong>输入:</strong></p>
 | 
			
		||||
 | 
			
		||||
<p>customer_transactions 表:</p>
 | 
			
		||||
 | 
			
		||||
<pre class="example-io">
 | 
			
		||||
+----------------+-------------+------------------+--------+------------------+
 | 
			
		||||
| 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           |
 | 
			
		||||
+----------------+-------------+------------------+--------+------------------+
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>输出:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre class="example-io">
 | 
			
		||||
+-------------+
 | 
			
		||||
| customer_id |
 | 
			
		||||
+-------------+
 | 
			
		||||
| 101         |
 | 
			
		||||
| 104         |
 | 
			
		||||
+-------------+
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>解释:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><strong>客户 101</strong>:
 | 
			
		||||
 | 
			
		||||
	<ul>
 | 
			
		||||
		<li>购买交易:4 (IDs: 1, 2, 3, 4) </li>
 | 
			
		||||
		<li>退款交易:0</li>
 | 
			
		||||
		<li>退款率:0/4 = 0%(少于 20%)</li>
 | 
			
		||||
		<li>活跃时期:1 月 5 日到 2 月 20 日 = 46 天(至少 30 天)</li>
 | 
			
		||||
		<li>符合忠诚客户条件</li>
 | 
			
		||||
	</ul>
 | 
			
		||||
	</li>
 | 
			
		||||
	<li><strong>客户 102</strong>:
 | 
			
		||||
	<ul>
 | 
			
		||||
		<li>购买交易:3 (IDs: 5, 6, 9) </li>
 | 
			
		||||
		<li>退款交易:2 (IDs: 7, 8)</li>
 | 
			
		||||
		<li>退款率:2/5 = 40% (超过 20%) </li>
 | 
			
		||||
		<li>不符合忠诚客户条件</li>
 | 
			
		||||
	</ul>
 | 
			
		||||
	</li>
 | 
			
		||||
	<li><strong>客户 103</strong>:
 | 
			
		||||
	<ul>
 | 
			
		||||
		<li>购买交易:3 (IDs: 10, 11, 12) </li>
 | 
			
		||||
		<li>退款交易:0</li>
 | 
			
		||||
		<li>退款率:0/3 = 0%(少于 20%)</li>
 | 
			
		||||
		<li>活跃时期:1 月 1 日到 1 月 3 日 = 2 天(少于 30 天)</li>
 | 
			
		||||
		<li>不符合忠诚客户条件</li>
 | 
			
		||||
	</ul>
 | 
			
		||||
	</li>
 | 
			
		||||
	<li><strong>客户 104</strong>:
 | 
			
		||||
	<ul>
 | 
			
		||||
		<li>购买交易:5 (IDs: 13, 14, 15, 16, 17) </li>
 | 
			
		||||
		<li>退款交易:1 (ID: 18)</li>
 | 
			
		||||
		<li>退款率:1/6 = 16.67%(少于 20%)</li>
 | 
			
		||||
		<li>活跃时期:1 月 1 日到 3 月 15 日 = 73 天(至少 30 天)</li>
 | 
			
		||||
		<li>符合忠诚客户条件</li>
 | 
			
		||||
	</ul>
 | 
			
		||||
	</li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
<p>结果表以 customer_id 升序排序。</p>
 | 
			
		||||
</div>
 | 
			
		||||
		Reference in New Issue
	
	Block a user