当前位置:网站首页>1484. 按日期分组销售产品
1484. 按日期分组销售产品
2022-08-05 02:32:00 【只是六号z】
1484. 按日期分组销售产品
前言
表 Activities:
+-------------+---------+
| 列名 | 类型 |
+-------------+---------+
| sell_date | date |
| product | varchar |
+-------------+---------+
此表没有主键,它可能包含重复项。
此表的每一行都包含产品名称和在市场上销售的日期。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/group-sold-products-by-the-date
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
编写一个 SQL 查询来查找每个日期、销售的不同产品的数量及其名称。
每个日期的销售产品名称应按词典序排列。
返回按 sell_date 排序的结果表。
查询结果格式如下例所示。
示例 1:
输入:
Activities 表:
+------------+-------------+
| 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 |
+------------+-------------+
输出:
+------------+----------+------------------------------+
| sell_date | num_sold | products |
+------------+----------+------------------------------+
| 2020-05-30 | 3 | Basketball,Headphone,T-shirt |
| 2020-06-01 | 2 | Bible,Pencil |
| 2020-06-02 | 1 | Mask |
+------------+----------+------------------------------+
解释:
对于2020-05-30,出售的物品是 (Headphone, Basketball, T-shirt),按词典序排列,并用逗号 ',' 分隔。
对于2020-06-01,出售的物品是 (Pencil, Bible),按词典序排列,并用逗号分隔。
对于2020-06-02,出售的物品是 (Mask),只需返回该物品名。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/group-sold-products-by-the-date
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
count + group_concat + separator
select
sell_date,
// 统计数量
count(distinct product) as num_sold,
// group_concat将组中的字符串连接
// separator 使用指定符号隔开
group_concat(distinct product order by product separator ',') as products
from activities
group by sell_date
order by sell_date;
边栏推荐
- C语言日记 9 if的3种语句
- 开篇-开启全新的.NET现代应用开发体验
- select tag custom style
- 2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from
- hypervisor相关的知识点
- 树表的查找
- ARM Mailbox
- C language implements a simple number guessing game
- [机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
- Using OpenVINO to implement the flying paddle version of the PGNet inference program
猜你喜欢

2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!

【LeetCode刷题】-数之和专题(待补充更多题目)

如何逐步执行数据风险评估

正则表达式,匹配中间的某一段字符串

LeetCode使用最小花费爬楼梯----dp问题

iNFTnews | What can NFTs bring to the sports industry and fans?

What should I do if the self-incrementing id of online MySQL is exhausted?

select 标签自定义样式
![01 [Foreword Basic Use Core Concepts]](/img/90/67537d5fad28d68766ca85b887839e.png)
01 [Foreword Basic Use Core Concepts]

C语言实现简单猜数字游戏
随机推荐
【C语言】详解栈和队列(定义、销毁、数据的操作)
The 2022 EdgeX China Challenge will be grandly opened on August 3
Short domain name bypass and xss related knowledge
ARM Mailbox
如何看待自己的羞愧感
C language diary 9 3 kinds of statements of if
开篇-开启全新的.NET现代应用开发体验
解决connect: The requested address is not valid in its context
Flink 1.15.1 集群搭建(StandaloneSession)
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
select tag custom style
散列表的查找(哈希表)
转:查尔斯·汉迪:你是谁,比你做什么更重要
特殊矩阵的压缩存储
C学生管理系统 指定位置插入学生节点
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
02 [Development Server Resource Module]
【日常训练】1403. 非递增顺序的最小子序列
Hypervisor related knowledge points