当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- GPS坐标转百度地图坐标的方法
- Luogu problem list: [mathematics 1] basic mathematics problems
- Synthetic keyword and NBAC mechanism
- In depth learning
- Kubernetes notes (VII) kuberetes scheduling
- Oracle database synonym creation
- [teacher Zhao Yuqiang] RDB persistence of redis
- [teacher Zhao Yuqiang] index in mongodb (Part 1)
- [teacher Zhao Yuqiang] MySQL flashback
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
猜你喜欢

Loss function in pytorch multi classification

pytorch 多分类中的损失函数

Project summary --2 (basic use of jsup)

Oauth2.0 - Introduction and use and explanation of authorization code mode

Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Cesium 点击获三维坐标(经纬度高程)

项目总结--04

GPS坐标转百度地图坐标的方法
![[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history](/img/18/f91d3d21a39743231d01f2e4015ef8.jpg)
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
随机推荐
[system design] proximity service
BeanDefinitionRegistryPostProcessor
深度学习,从一维特性输入到多维特征输入引发的思考
Migrate data from Mysql to tidb from a small amount of data
Yum is too slow to bear? That's because you didn't do it
It is said that the operation and maintenance of shell scripts are paid tens of thousands of yuan a month!!!
Difference between shortest path and minimum spanning tree
Tabbar settings
1. 两数之和
Introduction to software engineering
23 design models
ThreadLocal的简单理解
[teacher Zhao Yuqiang] RDB persistence of redis
Kubesphere - build MySQL master-slave replication structure
Oracle Database Introduction
项目总结--01(接口的增删改查;多线程的使用)
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Kubesphere - build Nacos cluster
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
Synthetic keyword and NBAC mechanism