当前位置:网站首页>1484. Sell Products by Date
1484. Sell Products by Date
2022-08-05 02:33:00 【just six 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_concatConcatenate strings in groups
// separator separated by the specified symbol
group_concat(distinct product order by product separator ',') as products
from activities
group by sell_date
order by sell_date;
边栏推荐
- 01 [Foreword Basic Use Core Concepts]
- 线性表的查找
- 使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
- Semi-Decentralized Federated Learning for Cooperative D2D Local Model Aggregation
- 力扣-二叉树的前序遍历、中序遍历、后序遍历
- [ROS](10)ROS通信 —— 服务(Service)通信
- Common hardware delays
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
- Note that Weifang generally needs to pay attention to issuing invoices
- [C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
猜你喜欢
LeetCode uses the minimum cost to climb the stairs----dp problem
多线程(2)
学习笔记-----左偏树
DAY23:命令执行&代码执行漏洞
使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
The 20th day of the special assault version of the sword offer
Data to enhance Mixup principle and code reading
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
Ant Sword Advanced Module Development
SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
随机推荐
程序员的七夕浪漫时刻
mysql tree structure query problem
注意潍坊开具发票一般需要注意
网络安全与元宇宙:找出薄弱环节
1873. The special bonus calculation
the mechanism of ideology
线性表的查找
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
1873. 计算特殊奖金
SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
Chinese characters to Pinyin
shell statement to modify txt file or sh file
dmp(dump)转储文件
C学生管理系统 头添加学生节点
1484. 按日期分组销售产品
Go 微服务开发框架 DMicro 的设计思路
Error: Not a signal or slot declaration
02 [Development Server Resource Module]
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
View handler stepping record