当前位置:网站首页>SQL implementation merges multiple rows of records into one row
SQL implementation merges multiple rows of records into one row
2022-07-03 06:28:00 【Reasonable meow~~】
SQL Realize merging multiple lines of records into one line
We are in the process of data development , It's a common demand , Is to merge multiple rows into one row , And separated by specific characters .
1、 Before data processing
2, Result data display
3,hive Processing mode
stay hive Inside , use concat_ws Function processing
Format : concat_ws(‘ Separator ’,collect_set/collect_list( Field ))
Parameter interpretation :
concat_ws: Merge multiple lines into one line of functions
collect_set: Composite array , The data has been de duplicated
collect_list: Composite array , Data not de duplicated
SQL Script :
select school,concat_ws(',',collect_set(name)) from student
group by school;
4,MySQL Processing mode
GROUP_CONCAT( Field Separator )
Be careful :MySQL stay GROUP_CONCAT Function , Weight removal needs to be used distinct keyword , If you need to sort before merging , You can also use order by keyword .
select school,GROUP_CONCAT(name,',') from student
group by school;
I'm meow , If you have problems, please communicate at any time ~~~
边栏推荐
- Heap sort and priority queue
- opencv
- Important knowledge points of redis
- Naive Bayes in machine learning
- 从小数据量分库分表 MySQL 合并迁移数据到 TiDB
- Example of joint use of ros+pytoch (semantic segmentation)
- MATLAB如何修改默认设置
- Oauth2.0 - Introduction and use and explanation of authorization code mode
- Luogu problem list: [mathematics 1] basic mathematics problems
- Cesium 点击获三维坐标(经纬度高程)
猜你喜欢
How to scan when Canon c3120l is a network shared printer
Simple understanding of ThreadLocal
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
Time format record
YOLOV3学习笔记
Une exploration intéressante de l'interaction souris - pointeur
Advanced technology management - do you know the whole picture of growth?
Method of converting GPS coordinates to Baidu map coordinates
技术管理进阶——你了解成长的全貌吗?
ssh链接远程服务器 及 远程图形化界面的本地显示
随机推荐
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Migrate data from Amazon aurora to tidb
Tabbar settings
表达式的动态解析和计算,Flee用起来真香
23 design models
致即将毕业大学生的一封信
认识弹性盒子flex
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
About the difference between count (1), count (*), and count (column name)
The most classic 100 sentences in the world famous works
YOLOV3学习笔记
SSH link remote server and local display of remote graphical interface
Creating postgre enterprise database by ArcGIS
Interface test weather API
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
[untitled] 5 self use history
从小数据量 MySQL 迁移数据到 TiDB
Selenium ide installation recording and local project maintenance
Various usages of MySQL backup database to create table select and how many days are left
ThreadLocal的简单理解