当前位置:网站首页>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列转行函数指的是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
边栏推荐
- 电商系统中常见的9大坑,你踩过没?
- 电子协会 C语言 1级 33 、奇偶数判断
- 【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
- Design and implementation of radio energy transmission system
- Laravel artisan 常用命令
- Self drawing of menu items and CListBox items
- Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
- PR second training
- D discard the virtual recovery method
- Ks006 student achievement management system based on SSM
猜你喜欢
![[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card](/img/99/53b0ae47bada8b0d4db30d0517fe3d.jpg)
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card

医药管理系统(大一下C语言课设)
![[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility](/img/8b/e51867cfe9d200ac385e1d1f01e4b3.jpg)
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility

Memorabilia of domestic database in June 2022

企业应该选择无服务器计算吗?

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

开发工具创新升级,鲲鹏推进计算产业“竹林”式生长

并发编程的三大核心问题

SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
随机推荐
Based on configured schedule, the given trigger will never fire
Design and implementation of radio energy transmission system
II Basic structure of radio energy transmission system
游戏思考15:全区全服和分区分服的思考
企业应该选择无服务器计算吗?
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
Unity AssetBundle subcontracting
卷积神经网络(包含代码与相应图解)
KS006基于SSM实现学生成绩管理系统
Penser au jeu 15: penser au service complet et au sous - service
Cross domain? Homology? Understand what is cross domain at once
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
Convolutional neural network (including code and corresponding diagram)
正则表达式学习笔记
机器学习基本概念
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
如何用一款产品推动「品牌的惊险一跃」?
JMeter (II) - install the custom thread groups plug-in
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me