当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- It is said that the operation and maintenance of shell scripts are paid tens of thousands of yuan a month!!!
- Virtual memory technology sharing
- Oracle Database Introduction
- BeanDefinitionRegistryPostProcessor
- Sorry, this user does not exist!
- 多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
- 1. 兩數之和
- Luogu problem list: [mathematics 1] basic mathematics problems
- Nacos service installation
- 1. Somme des deux nombres
猜你喜欢

Zhiniu stock project -- 05

Interesting research on mouse pointer interaction

Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11

理解 期望(均值/估计值)和方差

最大似然估计,散度,交叉熵

phpstudy设置项目可以由局域网的其他电脑可以访问
![[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

.NET程序配置文件操作(ini,cfg,config)

Pytorch builds the simplest version of neural network

CKA certification notes - CKA certification experience post
随机推荐
1. Somme des deux nombres
In depth learning
Mysql database table export and import with binary
使用conda创建自己的深度学习环境
Oracle database synonym creation
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
技术管理进阶——你了解成长的全貌吗?
PMP notes
从小数据量 MySQL 迁移数据到 TiDB
Synthetic keyword and NBAC mechanism
Cesium entity (entities) entity deletion method
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
Core principles and source code analysis of disruptor
Maximum likelihood estimation, divergence, cross entropy
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
Oauth2.0 - using JWT to replace token and JWT content enhancement
Introduction to software engineering
Some thoughts on machine learning
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)