1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 02:30:28 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/按日期分组销售产品 [group-sold-products-by-the-date].html

52 lines
1.8 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>&nbsp;<code>Activities</code></p>
<pre>
+-------------+---------+
| 列名 | 类型 |
+-------------+---------+
| sell_date | date |
| product | varchar |
+-------------+---------+
2023-12-09 18:42:21 +08:00
该表没有主键(具有唯一值的列)。它可能包含重复项。
2022-03-27 20:37:52 +08:00
此表的每一行都包含产品名称和在市场上销售的日期。
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>编写解决方案找出每个日期、销售的不同产品的数量及其名称。<br />
2022-03-27 20:37:52 +08:00
每个日期的销售产品名称应按词典序排列。<br />
返回按&nbsp;<code>sell_date</code> 排序的结果表。<br />
2023-12-09 18:42:21 +08:00
结果表结果格式如下例所示。</p>
2022-03-27 20:37:52 +08:00
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<code><strong>输入:</strong>
Activities</code> 表:
+------------+-------------+
| sell_date | product |
+------------+-------------+
| 2020-05-30 | Headphone |
| 2020-06-01 | Pencil |
| 2020-06-02 | Mask |
| 2020-05-30 | Basketball |
| 2020-06-01 | Bible |
| 2020-06-02 | Mask |
| 2020-05-30 | T-Shirt |
+------------+-------------+
<strong>输出:</strong>
+------------+----------+------------------------------+
| sell_date | num_sold | products |
+------------+----------+------------------------------+
| 2020-05-30 | 3 | Basketball,Headphone,T-shirt |
| 2020-06-01 | 2 | Bible,Pencil |
| 2020-06-02 | 1 | Mask |
+------------+----------+------------------------------+
<strong>解释:</strong>
对于2020-05-30出售的物品是 (Headphone, Basketball, T-shirt),按词典序排列,并用逗号 ',' 分隔。
对于2020-06-01出售的物品是 (Pencil, Bible),按词典序排列,并用逗号分隔。
2023-12-09 18:42:21 +08:00
对于2020-06-02出售的物品是 (Mask),只需返回该物品名。
</pre>