当前位置:网站首页>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;
边栏推荐
- Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
- KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
- 从零到一快速学会三子棋
- select tag custom style
- Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
- 力扣-二叉树的前序遍历、中序遍历、后序遍历
- Industry case | insurance companies of the world's top 500 construction standards can be used to drive the business analysis system
- 特殊矩阵的压缩存储
- VSCode Change Default Terminal 如何修改vscode的默认terminal
猜你喜欢

select tag custom style

HOG feature study notes

2022 EdgeX中国挑战赛8月3日即将盛大开幕

Regular expression to match a certain string in the middle

CPDA|运营人如何从负基础学会数据分析(SQL)

如何基于OpenVINO POT工具简单实现对模型的量化压缩

【MySQL series】- Does LIKE query start with % will make the index invalid?

Pisanix v0.2.0 released | Added support for dynamic read-write separation

leetcode 15

Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
随机推荐
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
VSCode Change Default Terminal 如何修改vscode的默认terminal
释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
SuperMap支持的国产环境汇总
散列表的查找(哈希表)
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
意识形态的机制
Access Characteristics of Constructor under Inheritance Relationship
PHP Skills Assessment
【MySQL series】- Does LIKE query start with % will make the index invalid?
线上MySQL的自增id用尽怎么办?
英特尔 XDC 2022 精彩回顾:共建开放生态,释放“基建”潜能
How do programmers without objects spend the Chinese Valentine's Day
ARM Mailbox
甘特图来啦,项目管理神器,模板直接用
Programmer's list of sheep counting when insomnia | Daily anecdote
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
HOG特征学习笔记
RAID disk array