当前位置:网站首页>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;
我是喵,有问题随时沟通哟~~~
边栏推荐
- Disruptor learning notes: basic use, core concepts and principles
- Leetcode solution - 02 Add Two Numbers
- Why should there be a firewall? This time xiaowai has something to say!!!
- Pytorch dataloader implements minibatch (incomplete)
- Sorry, this user does not exist!
- Kubesphere - build Nacos cluster
- 理解 YOLOV1 第一篇 预测阶段
- [teacher Zhao Yuqiang] kubernetes' probe
- 1. 两数之和
- Jedis source code analysis (II): jediscluster module source code analysis
猜你喜欢
[teacher Zhao Yuqiang] index in mongodb (Part 2)
[teacher Zhao Yuqiang] RDB persistence of redis
phpstudy设置项目可以由局域网的其他电脑可以访问
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Kubernetes notes (10) kubernetes Monitoring & debugging
Creating postgre enterprise database by ArcGIS
Zhiniu stock -- 03
Oauth2.0 - explanation of simplified mode, password mode and client mode
Oauth2.0 - using JWT to replace token and JWT content enhancement
Redis cluster creation, capacity expansion and capacity reduction
随机推荐
1. Sum of two numbers
[system design] proximity service
从小数据量 MySQL 迁移数据到 TiDB
ThreadLocal的简单理解
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
Decision tree of machine learning
Introduction to software engineering
使用conda创建自己的深度学习环境
Oauth2.0 - Introduction and use and explanation of authorization code mode
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
项目总结--01(接口的增删改查;多线程的使用)
Mysql
It is said that the operation and maintenance of shell scripts are paid tens of thousands of yuan a month!!!
Understand the first prediction stage of yolov1
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Apple submitted the new MAC model to the regulatory database before the spring conference
When PHP uses env to obtain file parameters, it gets strings
Beandefinitionregistrypostprocessor
Mysql database
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface