当前位置:网站首页>SQL实现将多行记录合并成一行
SQL实现将多行记录合并成一行
2022-07-28 22:17:00 【m0_67403013】
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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- 【微服务】Nacos集群搭建以及加载文件配置
- Create AP hotspots for imx6 development board QT system based on rtl8723 cross compile iptables
- 【详细超简单】如何使用WebSocket链接
- pycharm新建项目
- With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally
- 请简述list,set,map类型的集合的各自特点(简述三种不同的继承方式下)
- 实时数仓:美团点评Flink的实时数仓应用分享
- Uricase - Characteristics of uricase in Worthington pig liver:
- Review of categories 1-4
- 考过HCIP入职心仪公司,分享华为认证学习经历及心得
猜你喜欢

失败率高达80%,数字化转型如何正确完成战略规划?

Worthington丨STEMxyme的分类和测定方法

多传感器融合定位(一)——3D激光里程计

Explanation of history and chemical properties of Worthington ribonuclease B

DevOps在物联网解决方案中的应用

Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan

【C】逆序字符串(俩种递归思路)

Compose 的声明式代码如此简洁?

【C】喝汽水,找单身狗问题

CANoe应用案例之DoIP通信
随机推荐
Leetcode60. 排列序列
通配符 SSL/TLS 证书
Connection pool - return connection details (Part 2)
CMake 基础学习
CANoe应用案例之DoIP通信
pycharm新建项目
leetcode 763. Partition Labels 划分字母区间(中等)
基因组 DNA 分离丨Worthington核糖核酸酶A
【TA-霜狼_may-《百人计划》】图形3.6 纹理压缩——包体瘦身术
Jincang database kingbasees client Programming Interface Guide - ODBC feature support constraints
【C】喝汽水,找单身狗问题
PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM
脲酶丨Worthington杰克豆脲酶的特性及测定方案
Android studio连接MySQL并完成简单的登录注册功能
Multi sensor fusion positioning (I) -- 3D laser odometer
VS2005 accesses the setting method "recommended collection" of vss2005 through sourceoffsite
Where is the DP interface of desktop computer (what if the host has no DP interface)
Oracle创建表空间和用户
Zabbix 5.0 使用自带Redis模版监控
PowerCLi 批量添加esxi到vCenter