当前位置:网站首页>Database daily question - day 20: selling products by date
Database daily question - day 20: selling products by date
2022-06-22 23:52:00 【InfoQ】
One 、 Problem description
Activities+-------------+---------+
| Name | type |
+-------------+---------+
| sell_date | date |
| product | varchar |
+-------------+---------+
This table has no primary key , It may contain duplicates .
Each row of this table contains the product name and the date of sale in the market .
SQLsell_dateTwo 、 Subject requirements
Examples
Input :
Activities surface :
+------------+-------------+
| 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 |
+------------+-------------+
Output :
+------------+----------+------------------------------+
| sell_date | num_sold | products |
+------------+----------+------------------------------+
| 2020-05-30 | 3 | Basketball,Headphone,T-shirt |
| 2020-06-01 | 2 | Bible,Pencil |
| 2020-06-02 | 1 | Mask |
+------------+----------+------------------------------+
explain :
about 2020-05-30, The items for sale are (Headphone, Basketball, T-shirt), Arrange in dictionary order , And use commas ',' Separate .
about 2020-06-01, The items for sale are (Pencil, Bible), Arrange in dictionary order , Separated by a comma .
about 2020-06-02, The items for sale are (Mask), Just return the item name .
Investigate
1. Aggregate functions 、 logic analysis
2. It is recommended to use time 10~25min
3、 ... and 、 Problem analysis
group_concat,Four 、 coded
select sell_date,count(distinct product) as 'num_sold',
group_concat(distinct product order by product separator ',') as 'products'
from Activities
group by sell_date
order by sell_date
5、 ... and 、 test result



边栏推荐
- Various schemes for lazy loading of pictures
- Leakcanary source code (2)
- Introduction to the unique variable reading and writing function of Kunlun distributed database
- Sword finger offer 07 Rebuild binary tree
- [go] go polymorphism
- 一文简述:钓鱼攻击知多少
- KunlunDB查询优化(三)排序下推
- 昆仑分布式数据库Sequence功能及其实现机制
- c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试
- 为什么现在大家都不用外键了(二)?
猜你喜欢

Isolation level of transaction system

IPV4的未来替代品!一文读懂IPV6的优势特点和地址类型

KunlunDB查询优化(二)Project和Filter下推

语义分割新范式!StructToken:对per-pixel 分类范式的重新思考

canvas生成海报

Introduction to the unique variable reading and writing function of Kunlun distributed database

Future alternatives to IPv4! Read the advantages, features and address types of IPv6
声网多人视频录制与合成支持掉线再录制 | 掘金技术征文

事务系统的隔离级别
![[arm] it is reported that horizontal display is set for LVDS screen of rk3568 development board](/img/3c/717b4a481bfff1d37e3c271f37a7d6.png)
[arm] it is reported that horizontal display is set for LVDS screen of rk3568 development board
随机推荐
Php7.3 error undefined function simplexml_ load_ string()
冒泡排序 指针
PHP7.3报错undefined function simplexml_load_string()
使用GetX构建更优雅的Flutter页面结构
昆仑分布式数据库技术优势
Redistemplate encountered problems with \x00
C language greedy snake
OJ每日一练——过滤多余的空格
Introduction to the unique variable reading and writing function of Kunlun distributed database
Digital data was invited to participate in Nantong enterprise digital transformation Seminar
[STM32 skill] use the hardware I2C of STM32 Hal library to drive rx8025t real-time clock chip
软件构造课程ADT与OOP理解
#yyds干货盘点# 解决剑指offer:把二叉树打印成多行
[go] go polymorphism
OJ daily practice - find the first character that only appears once
Digital data depth | about software self-control, source code left, no code right
ECMAScript6新特性
美团基于 Flink 的实时数仓平台建设新进展
[go] go mod mode, package 12import/add is not in goroot
Array and string offset access syntax with curly braces is no longer support