当前位置:网站首页>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;
边栏推荐
- 《.NET物联网从零开始》系列
- 高数_复习_第1章:函数、极限、连续
- LPQ (local phase quantization) study notes
- Programmer's list of sheep counting when insomnia | Daily anecdote
- 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
- [深入研究4G/5G/6G专题-51]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-11-高可靠性技术-2-链路自适应增强(根据无线链路状态动态选择高可靠性MCS)
- Common hardware delays
- 正则表达式,匹配中间的某一段字符串
- 甘特图来啦,项目管理神器,模板直接用
- 回顾51单片机
猜你喜欢

2022-08-04:输入:去重数组arr,里面的数只包含0~9。limit,一个数字。 返回:要求比limit小的情况下,能够用arr拼出来的最大数字。 来自字节。

基于左序遍历的数据存储实践

RAID磁盘阵列

The 2022 EdgeX China Challenge will be grandly opened on August 3

树形查找(二叉查找树)

How do programmers without objects spend the Chinese Valentine's Day

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

Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?
![[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)](/img/ee/6b52072c841af99488dc0c1141c74c.png)
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
![02 [Development Server Resource Module]](/img/60/f77ed0bb0e5654c9dcd70b73a5bee8.png)
02 [Development Server Resource Module]
随机推荐
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
网络安全与元宇宙:找出薄弱环节
【C语言】详解栈和队列(定义、销毁、数据的操作)
Access Characteristics of Constructor under Inheritance Relationship
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
Regular expression to match a certain string in the middle
回顾51单片机
力扣-二叉树的最大的深度
在这个超连接的世界里,你的数据安全吗
SuperMap支持的国产环境汇总
Opening - Open a new .NET modern application development experience
使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
Common hardware delays
C student management system head to add a student node
C language implements a simple number guessing game
继承关系下构造方法的访问特点
".NET IoT from scratch" series
01 [Foreword Basic Use Core Concepts]
C student management system Find student nodes based on student ID
【存储】曙光存储DS800-G35 ISCSI各映射LUN给服务器