当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- Oracle database synonym creation
- Exportation et importation de tables de bibliothèque avec binaires MySQL
- Svn branch management
- BeanDefinitionRegistryPostProcessor
- [teacher Zhao Yuqiang] Cassandra foundation of NoSQL database
- Decision tree of machine learning
- Detailed explanation of findloadedclass
- [teacher Zhao Yuqiang] RDB persistence of redis
- arcgis创建postgre企业级数据库
- Creating postgre enterprise database by ArcGIS
猜你喜欢

Kubernetes notes (VIII) kubernetes security

輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷

深度学习,从一维特性输入到多维特征输入引发的思考

Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)

Merge and migrate data from small data volume, sub database and sub table Mysql to tidb

项目总结--04

Zhiniu stock -- 03

Simple handwritten ORM framework

JDBC connection database steps
随机推荐
phpstudy设置项目可以由局域网的其他电脑可以访问
Exportation et importation de tables de bibliothèque avec binaires MySQL
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Kubernetes cluster environment construction & Deployment dashboard
. Net program configuration file operation (INI, CFG, config)
深入解析kubernetes controller-runtime
How to create and configure ZABBIX
Leetcode solution - 02 Add Two Numbers
Core principles and source code analysis of disruptor
SVN分支管理
有意思的鼠标指针交互探究
pytorch 多分类中的损失函数
tabbar的设置
Common interview questions
Luogu problem list: [mathematics 1] basic mathematics problems
【系统设计】邻近服务
The most responsible command line beautification tutorial
Deep learning, thinking from one dimensional input to multi-dimensional feature input
Why should there be a firewall? This time xiaowai has something to say!!!