1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/奇数和偶数交易 [odd-and-even-transactions].html
2024-08-06 08:46:50 +08:00

84 lines
2.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>表:<code>transactions</code></p>
<pre>
+------------------+------+
| Column Name | Type |
+------------------+------+
| transaction_id | int |
| amount | int |
| transaction_date | date |
+------------------+------+
transactions_id 列唯一标识了表中的每一行。
这张表的每一行包含交易 id金额总和和交易日期。
</pre>
<p>编写一个解决方案来查找每天 <strong>奇数</strong> 交易金额和 <strong>偶数</strong> 交易金额的 <strong>总和</strong>。如果某天没有奇数或偶数交易,显示为&nbsp;<code>0</code></p>
<p>返回结果表以&nbsp;<code>transaction_date</code> <strong>升序</strong>&nbsp;排序。</p>
<p>结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例:</strong></p>
<div class="example-block">
<p><b>输入:</b></p>
<p><code>transactions</code> 表:</p>
<pre class="example-io">
+----------------+--------+------------------+
| transaction_id | amount | transaction_date |
+----------------+--------+------------------+
| 1 | 150 | 2024-07-01 |
| 2 | 200 | 2024-07-01 |
| 3 | 75 | 2024-07-01 |
| 4 | 300 | 2024-07-02 |
| 5 | 50 | 2024-07-02 |
| 6 | 120 | 2024-07-03 |
+----------------+--------+------------------+
</pre>
<p><strong>输出:</strong></p>
<pre class="example-io">
+------------------+---------+----------+
| transaction_date | odd_sum | even_sum |
+------------------+---------+----------+
| 2024-07-01 | 75 | 350 |
| 2024-07-02 | 0 | 350 |
| 2024-07-03 | 0 | 120 |
+------------------+---------+----------+
</pre>
<p><strong>解释:</strong></p>
<ul>
<li>对于交易日期:
<ul>
<li>2024-07-01:
<ul>
<li>奇数交易金额总和75</li>
<li>偶数交易金额总和150 + 200 = 350</li>
</ul>
</li>
<li>2024-07-02:
<ul>
<li>奇数交易金额总和0</li>
<li>偶数交易金额总和300 + 50 = 350</li>
</ul>
</li>
<li>2024-07-03:
<ul>
<li>奇数交易金额总和0</li>
<li>偶数交易金额总和120</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><b>注意:</b>输出表以&nbsp;<code>transaction_date</code>&nbsp;升序排序。</p>
</div>