当前位置:网站首页>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;
边栏推荐
- 1873. 计算特殊奖金
- 树表的查找
- Error: Not a signal or slot declaration
- Common hardware delays
- [深入研究4G/5G/6G专题-51]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-11-高可靠性技术-2-链路自适应增强(根据无线链路状态动态选择高可靠性MCS)
- HDU 1114:Piggy-Bank ← 完全背包问题
- [LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
- 开源协议说明LGPL
- What should I do if the self-incrementing id of online MySQL is exhausted?
- mysql树状结构查询问题
猜你喜欢

Cloud Native (32) | Introduction to Platform Storage System in Kubernetes

The 20th day of the special assault version of the sword offer

【OpenCV 图像处理2】:OpenCV 基础知识

C语言实现简单猜数字游戏

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

海量服务实例动态化管理

01 【前言 基础使用 核心概念】

matlab绘制用颜色表示模值大小的箭头图

多线程(2)

LeetCode uses the minimum cost to climb the stairs----dp problem
随机推荐
View handler 踩坑记录
leetcode-另一棵树的子树
Programmer's Tanabata Romantic Moment
"Dilili, wait for the lights, wait for the lights", the prompt sound for safe production in the factory
Pisanix v0.2.0 released | Added support for dynamic read-write separation
Data to enhance Mixup principle and code reading
QT语言文件制作
Opening - Open a new .NET modern application development experience
matlab绘制用颜色表示模值大小的箭头图
海量服务实例动态化管理
Chinese characters to Pinyin
The 20th day of the special assault version of the sword offer
shell statement to modify txt file or sh file
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
1873. The special bonus calculation
627. 变更性别
常见的硬件延迟
1667. 修复表中的名字
C language diary 9 3 kinds of statements of if
Lexicon - the maximum depth of a binary tree