当前位置:网站首页>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;
边栏推荐
- Regular expression to match a certain string in the middle
- 【日常训练】1403. 非递增顺序的最小子序列
- How to deal with your own shame
- 【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?
- Pisanix v0.2.0 发布|新增动态读写分离支持
- Cloud Native (32) | Introduction to Platform Storage System in Kubernetes
- Compressed storage of special matrices
- SuperMap支持的国产环境汇总
- 【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
- 散列表的查找(哈希表)
猜你喜欢

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

使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号

Common hardware delays

Flink 1.15.1 集群搭建(StandaloneSession)

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

KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)

Using OpenVINO to implement the flying paddle version of the PGNet inference program
![[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)](/img/7b/8b3f1e4f0000aa34fc1f8fff485765.png)
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
![[ROS] (10) ROS Communication - Service Communication](/img/4d/4657f24bd7809abb4bdc4b418076f7.png)
[ROS] (10) ROS Communication - Service Communication

正则表达式,匹配中间的某一段字符串
随机推荐
ARM Mailbox
DAY23:命令执行&代码执行漏洞
Access Characteristics of Constructor under Inheritance Relationship
【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?
解决connect: The requested address is not valid in its context
Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
Solve connect: The requested address is not valid in its context
1527. 患某种疾病的患者
QStyle平台风格
C student management system head to add a student node
2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
js中try...catch和finally的用法
mysql树状结构查询问题
【 2 】 OpenCV image processing: basic knowledge of OpenCV
STM32使用stm32cubemx LL库系列教程
CPDA|运营人如何从负基础学会数据分析(SQL)
采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向
Amazon Cloud Technology joins hands with Thundersoft to build an AIoT platform for industry customers
力扣-二叉树的最大的深度
Regular expression to match a certain string in the middle