当前位置:网站首页>SQL实现将多行记录合并成一行
SQL实现将多行记录合并成一行
2022-07-03 06:05:00 【晓之以理的喵~~】
SQL实现将多行记录合并成一行
我们在数据开发的过程中,经常会遇到这样的需求,就是将多行合并为一行,并且用特定字符隔开。
1、数据处理前
2,结果数据展示
3,hive处理方式
在hive里面,用concat_ws函数处理
格式: concat_ws(‘分隔符’,collect_set/collect_list(字段))
参数释义:
concat_ws:多行合并一行函数
collect_set:合成数组,数据已去重
collect_list:合成数组, 数据未去重
SQL脚本:
select school,concat_ws(',',collect_set(name)) from student
group by school;
4,MySQL处理方式
GROUP_CONCAT(字段 分隔符)
注意:MySQL在GROUP_CONCAT函数中,去重需要使用distinct 关键字,如果需要先排序再合并,也可以使用order by 关键字。
select school,GROUP_CONCAT(name,',') from student
group by school;
我是喵,有问题随时沟通哟~~~
边栏推荐
- There is no one of the necessary magic skills PXE for old drivers to install!!!
- ThreadLocal的简单理解
- 项目总结--2(Jsoup的基本使用)
- BeanDefinitionRegistryPostProcessor
- Naive Bayes in machine learning
- pytorch 搭建神经网络最简版
- PMP笔记记录
- Kubernetes notes (VII) kuberetes scheduling
- Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
- Creating postgre enterprise database by ArcGIS
猜你喜欢
ThreadLocal的简单理解
技术管理进阶——你了解成长的全貌吗?
JDBC connection database steps
Oauth2.0 - Introduction and use and explanation of authorization code mode
pytorch 搭建神经网络最简版
理解 YOLOV1 第一篇 预测阶段
智牛股项目--05
Zhiniu stock -- 03
Oauth2.0 - using JWT to replace token and JWT content enhancement
Phpstudy setting items can be accessed by other computers on the LAN
随机推荐
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
Support vector machine for machine learning
理解 期望(均值/估计值)和方差
智牛股--03
Oauth2.0 - using JWT to replace token and JWT content enhancement
Bio, NiO, AIO details
PMP笔记记录
Cesium entity(entities) 实体删除方法
Sorry, this user does not exist!
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Mysql database table export and import with binary
Oauth2.0 - explanation of simplified mode, password mode and client mode
Leetcode solution - 01 Two Sum
CKA certification notes - CKA certification experience post
PMP notes
88. 合并两个有序数组
Oauth2.0 - Introduction and use and explanation of authorization code mode
项目总结--2(Jsoup的基本使用)
[teacher Zhao Yuqiang] use the catalog database of Oracle
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)