当前位置:网站首页>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;
边栏推荐
- VSCode Change Default Terminal 如何修改vscode的默认terminal
- 北斗三号短报文终端露天矿山高边坡监测方案
- mysql tree structure query problem
- 百日刷题计划 ———— DAY2
- C language implements a simple number guessing game
- Snapback - same tree
- Regular expression to match a certain string in the middle
- View handler 踩坑记录
- 散列表的查找(哈希表)
- 【日常训练】1403. 非递增顺序的最小子序列
猜你喜欢
![[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?](/img/81/2dcb61fd6c30f726804c73cf2b3384.jpg)
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?

Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中

甘特图来啦,项目管理神器,模板直接用

select tag custom style

虚拟内存原理与技术

DAY22:sqli-labs 靶场通关wp(Less01~~Less20)

蚁剑高级模块开发

lua学习

【LeetCode刷题】-数之和专题(待补充更多题目)

Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
随机推荐
用@Mapper查询oracle的分区情况报错
协作D2D局部模型聚合的半分散联合学习
继承关系下构造方法的访问特点
View handler 踩坑记录
627. Change of gender
1667. 修复表中的名字
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
Images using redis cache Linux master-slave synchronization server hard drive full of moved to the new directory which points to be modified
The 22-07-31 weeks summary
云原生(三十二) | Kubernetes篇之平台存储系统介绍
J9数字货币论:web3的创作者经济是什么?
VSCode Change Default Terminal 如何修改vscode的默认terminal
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
Semi-Decentralized Federated Learning for Cooperative D2D Local Model Aggregation
DAY23: Command Execution & Code Execution Vulnerability
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
02 [Development Server Resource Module]
剑指offer专项突击版第20天
C语言日记 9 if的3种语句
Go 微服务开发框架 DMicro 的设计思路