当前位置:网站首页>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;
边栏推荐
- CPDA|运营人如何从负基础学会数据分析(SQL)
- Transfer Learning - Distant Domain Transfer Learning
- Introduction to SDC
- Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
- Unleashing the engine of technological innovation, Intel joins hands with ecological partners to promote the vigorous development of smart retail
- Quickly learn chess from zero to one
- C学生管理系统 据学号查找学生节点
- 重新审视分布式系统:永远不会有完美的一致性方案……
- DAY23: Command Execution & Code Execution Vulnerability
- Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
猜你喜欢
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
【 2 】 OpenCV image processing: basic knowledge of OpenCV
正则表达式,匹配中间的某一段字符串
CPDA|运营人如何从负基础学会数据分析(SQL)
DAY23: Command Execution & Code Execution Vulnerability
".NET IoT from scratch" series
LPQ(局部相位量化)学习笔记
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
编译预处理等细节
随机推荐
散列表的查找(哈希表)
甘特图来啦,项目管理神器,模板直接用
[ROS] (10) ROS Communication - Service Communication
leetcode 15
2022-08-04:输入:去重数组arr,里面的数只包含0~9。limit,一个数字。 返回:要求比limit小的情况下,能够用arr拼出来的最大数字。 来自字节。
leetcode-对称二叉树
LeetCode使用最小花费爬楼梯----dp问题
转:查尔斯·汉迪:你是谁,比你做什么更重要
Industry case | insurance companies of the world's top 500 construction standards can be used to drive the business analysis system
用@Mapper查询oracle的分区情况报错
亚马逊云科技 + 英特尔 + 中科创达为行业客户构建 AIoT 平台
lua学习
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
多线程(2)
程序员失眠时的数羊列表 | 每日趣闻
《.NET物联网从零开始》系列
Programmer's list of sheep counting when insomnia | Daily anecdote
SuperMap支持的国产环境汇总
采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向