当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- Type 1-5 components
- EN 1873 assembly accessories for roofing - plastic single roof lamps - CE certification
- Leetcode62. 不同路径
- Jincang database kingbasees client programming interface guide ODBC (5. Development process)
- 器利而工善,以RPA+LCAP赋能企业司库管理数字化升级
- Machine learning problem notes
- EN 1873屋面用装配附件.塑料单个屋面灯—CE认证
- 1-5 类式组件
- Compatibility description between kingbasees and Oracle (4. SQL)
- Pycharm new project
猜你喜欢

Leetcode61. 旋转链表

SAP temporary tablespace error handling

VMware VCSA 7.0 Install

Worthington - chemical properties and related studies of Worthington trypsin

基因组 DNA 分离丨Worthington核糖核酸酶A

PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM

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

ZABBIX 5.0 uses its own redis template for monitoring

Worthington核糖核酸测定详细攻略

Kingbasees client programming interface guide ODBC (4. Create data source)
随机推荐
Those "experiences and traps" in the data center
@Transactional 注解使用详解
Where is the DP interface of desktop computer (what if the host has no DP interface)
Leetcode63. 不同路径 II
Hutool official website (is hutool easy to use)
Worthington -- Specification of Worthington trypsin inhibitor
Eight performance analysis indicators of effective supply chain management (Part 1)
Worthington RNA determination detailed introduction
CANoe应用案例之DoIP通信
RHCE first day
尿酸酶丨Worthington猪肝尿酸酶的特征:
YOLOV5学习笔记(一)——原理概述
Build SSM project with JSP as view parser
Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click
Is the declarative code of compose so concise?
Multisensor fusion positioning (III) -- inertial technology
1-6 state and binding events
1-8 basic use of props
1-7 解决类中方法的this指向问题
websocket心跳机制(保活机制)