当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- [teacher Zhao Yuqiang] use the catalog database of Oracle
- Zhiniu stock project -- 04
- ThreadLocal的简单理解
- There is no one of the necessary magic skills PXE for old drivers to install!!!
- Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
- Kubesphere - set up redis cluster
- Detailed explanation of findloadedclass
- [teacher Zhao Yuqiang] Cassandra foundation of NoSQL database
- PHP用ENV获取文件参数的时候拿到的是字符串
- [teacher Zhao Yuqiang] index in mongodb (Part 2)
猜你喜欢
![[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

Jedis source code analysis (II): jediscluster module source code analysis

Tabbar settings

项目总结--2(Jsoup的基本使用)
![[teacher Zhao Yuqiang] use Oracle's tracking file](/img/0e/698478876d0dbfb37904d7b9ff9aca.jpg)
[teacher Zhao Yuqiang] use Oracle's tracking file

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

理解 YOLOV1 第一篇 预测阶段

23 design models

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

Project summary --2 (basic use of jsup)
随机推荐
Oracle database synonym creation
Advanced technology management - do you know the whole picture of growth?
Decision tree of machine learning
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
SVN分支管理
Naive Bayes in machine learning
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Phpstudy setting items can be accessed by other computers on the LAN
Beandefinitionregistrypostprocessor
Virtual memory technology sharing
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
Redis cluster creation, capacity expansion and capacity reduction
Oauth2.0 - explanation of simplified mode, password mode and client mode
In depth learning
Synthetic keyword and NBAC mechanism
Apifix installation
Cesium entity(entities) 实体删除方法
从小数据量 MySQL 迁移数据到 TiDB
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
【系统设计】邻近服务