mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
49 lines
1.9 KiB
HTML
49 lines
1.9 KiB
HTML
|
<p>表:<code>Transactions</code></p>
|
||
|
|
||
|
<pre>
|
||
|
+---------------+---------+
|
||
|
| Column Name | Type |
|
||
|
+---------------+---------+
|
||
|
| id | int |
|
||
|
| country | varchar |
|
||
|
| state | enum |
|
||
|
| amount | int |
|
||
|
| trans_date | date |
|
||
|
+---------------+---------+
|
||
|
id 是这个表的主键。
|
||
|
该表包含有关传入事务的信息。
|
||
|
state 列类型为 ["approved", "declined"] 之一。
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<p>编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。</p>
|
||
|
|
||
|
<p>以 <strong>任意顺序</strong> 返回结果表。</p>
|
||
|
|
||
|
<p>查询结果格式如下所示。</p>
|
||
|
|
||
|
<p> </p>
|
||
|
|
||
|
<p><strong>示例 1:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<code><strong>输入:</strong>
|
||
|
Transactions</code> table:
|
||
|
+------+---------+----------+--------+------------+
|
||
|
| id | country | state | amount | trans_date |
|
||
|
+------+---------+----------+--------+------------+
|
||
|
| 121 | US | approved | 1000 | 2018-12-18 |
|
||
|
| 122 | US | declined | 2000 | 2018-12-19 |
|
||
|
| 123 | US | approved | 2000 | 2019-01-01 |
|
||
|
| 124 | DE | approved | 2000 | 2019-01-07 |
|
||
|
+------+---------+----------+--------+------------+
|
||
|
<strong>输出:</strong>
|
||
|
+----------+---------+-------------+----------------+--------------------+-----------------------+
|
||
|
| month | country | trans_count | approved_count | trans_total_amount | approved_total_amount |
|
||
|
+----------+---------+-------------+----------------+--------------------+-----------------------+
|
||
|
| 2018-12 | US | 2 | 1 | 3000 | 1000 |
|
||
|
| 2019-01 | US | 1 | 1 | 2000 | 2000 |
|
||
|
| 2019-01 | DE | 1 | 1 | 2000 | 2000 |
|
||
|
+----------+---------+-------------+----------------+--------------------+-----------------------+</pre>
|