当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- Please briefly describe the respective characteristics of list, set and map type sets (briefly describe three different inheritance methods)
- Js判断数据类型的4种⽅式
- SAP oracle 复制新实例后数据库远程连接报错 ora-01031
- 基因组 DNA 分离丨Worthington核糖核酸酶A
- websocket心跳机制(保活机制)
- 连接池-归还连接详解(下)
- 1-7 解决类中方法的this指向问题
- 以JSP为视图解析器搭建SSM项目
- laptop外接显示器
- 迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
猜你喜欢

VMware VCSA 7.0 Install

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

电商数据模型设计

Is the declarative code of compose so concise?

Pycharm new project

Create AP hotspots for imx6 development board QT system based on rtl8723 cross compile iptables

VirtualLab基础实验教程-8.傅里叶变换(1)

【详细超简单】如何使用WebSocket链接

Worthington RNA determination detailed introduction

PHP 海报二维码合成
随机推荐
酪氨酸脱羧酶丨Worthington粪链球菌酪氨酸脱羧酶的特征
【C】atoi和offsetof的介绍和模拟实现
SAP temporary tablespace error handling
Powercl batch creates and manages virtual switches
ZABBIX 5.0 uses its own redis template for monitoring
Leetcode61. 旋转链表
多传感器融合定位(一)——3D激光里程计
Urease -- Characteristics and determination scheme of Worthington jack bean urease
Type 1-5 components
VMware VCSA 7.0 Install
Please briefly describe the respective characteristics of list, set and map type sets (briefly describe three different inheritance methods)
VirtualLab基础实验教程-8.傅里叶变换(1)
Eight performance analysis indicators of effective supply chain management (Part 1)
RHCE the next day
leetcode 763. Partition Labels 划分字母区间(中等)
With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally
Leetcode 763. partition labels divide alphabetic intervals (medium)
齐博建站指南(艾戈勒)
Compose 的声明式代码如此简洁?
VS2005 accesses the setting method "recommended collection" of vss2005 through sourceoffsite