当前位置:网站首页>mysql列转行函数指的是什么
mysql列转行函数指的是什么
2022-07-02 01:45:00 【亿速云】
mysql列转行函数指的是什么
这篇文章主要讲解了“mysql列转行函数指的是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“mysql列转行函数指的是什么”吧!
在mysql中,列转行函数是“group_concat()”函数;该函数用于将非空列值按照分组条件进行合并并最终返回,如果其中有空值则返回的结果是空,语法为“select group_concat(name separator ';')列名 from 表名;”。
本教程操作环境:windows10系统、mysql8.0.22版本、Dell G3电脑。
mysql列转行函数是什么
GROUP_CONCAT(expr)该函数将非空列值按照分组条件进行合并并最终返回。如果有空值,则返回为空
在MySQL中,如何将列转成一行?比如一个一个商品会属于多个分类(如华为手机可以是手机分类,也可以是数码分类),如何将此商品在一条数据中展现所有分类。
思路很简单,通过MySQL函数group_concat即可解决。
创建测试表:
create table test.test_mysql_liezhuanhang (id bigint auto_increment comment '主键',name varchar(100),age int(5),primary key (id))engine=innodb default charset=utf8mb4 comment='测试表'
导入测试数据:
insert into test.test_mysql_liezhuanhang (name, age) values ('李威', 18), ('李威', 19), ('李威', 18), ('李白', 20), ('李白', 20), ('李白', 19);
展现所有名字,以分号分割,默认以,
分割
select group_concat(name separator ';') concat from test.test_mysql_liezhuanhang ;
展现所有名字,并将相同名字去重
select group_concat(distinct name) concat from test.test_mysql_liezhuanhang ;
展现所有年龄,去重并以年龄升序排序
select group_concat(distinct age order by age) concat from test.test_mysql_liezhuanhang ;
感谢各位的阅读,以上就是“mysql列转行函数指的是什么”的内容了,经过本文的学习后,相信大家对mysql列转行函数指的是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
边栏推荐
- 分卷压缩,解压
- 电子协会 C语言 1级 32、计算2的幂
- Learn about servlets
- [IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
- There are spaces in the for loop variable in the shell -- IFS variable
- Data visualization in medical and healthcare applications
- Basic concepts of machine learning
- 机器学习基本概念
- Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
- SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
猜你喜欢
734. Energy stone (greed, backpack)
电商系统中常见的9大坑,你踩过没?
跨域?同源?一次搞懂什么是跨域
企业应该选择无服务器计算吗?
6-3 vulnerability exploitation SSH environment construction
1222. Password dropping (interval DP, bracket matching)
Liteos learning - first knowledge of development environment
GL Studio 5 installation and experience
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
卷積神經網絡(包含代碼與相應圖解)
随机推荐
【C#】使用正则校验内容
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
The difference between new and malloc
Based on configured schedule, the given trigger will never fire
NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
We should make clear the branch prediction
np. Where and torch Where usage
The role of artificial intelligence in network security
Luogu p1775 stone merger (weakened version)
matlab 使用 resample 完成重采样
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
城市选择器组件实现原理
Automatically browse pinduoduo products
Selection of field types for creating tables in MySQL database
Liteos learning - first knowledge of development environment
Game thinking 15: thinking about the whole region and sub region Services
The smart Park "ZhongGuanCun No.1" subverts your understanding of the park