当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- 輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
- Simple understanding of ThreadLocal
- The most responsible command line beautification tutorial
- Kubernetes notes (II) pod usage notes
- Detailed explanation of contextclassloader
- 理解 期望(均值/估计值)和方差
- 深度学习,从一维特性输入到多维特征输入引发的思考
- 从小数据量 MySQL 迁移数据到 TiDB
- Common interview questions
- 使用conda创建自己的深度学习环境
猜你喜欢
![[teacher Zhao Yuqiang] use the catalog database of Oracle](/img/0b/73a7d12caf955dff17480a907234ad.jpg)
[teacher Zhao Yuqiang] use the catalog database of Oracle

23 design models

Zhiniu stock -- 03

Svn branch management

Migrate data from Mysql to tidb from a small amount of data

Mysql

Creating postgre enterprise database by ArcGIS

Bio, NiO, AIO details

技术管理进阶——你了解成长的全貌吗?

Maximum likelihood estimation, divergence, cross entropy
随机推荐
Understand expectations (mean / estimate) and variances
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Luogu problem list: [mathematics 1] basic mathematics problems
Leetcode solution - 01 Two Sum
Some thoughts on machine learning
有意思的鼠标指针交互探究
Kubernetes cluster environment construction & Deployment dashboard
Exportation et importation de tables de bibliothèque avec binaires MySQL
Tabbar settings
Sorry, this user does not exist!
项目总结--2(Jsoup的基本使用)
深入解析kubernetes controller-runtime
Apple submitted the new MAC model to the regulatory database before the spring conference
arcgis创建postgre企业级数据库
BeanDefinitionRegistryPostProcessor
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Jedis source code analysis (I): jedis introduction, jedis module source code analysis
[teacher Zhao Yuqiang] MySQL flashback
深度学习,从一维特性输入到多维特征输入引发的思考