当前位置:网站首页>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列转行函数指的是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
边栏推荐
- new和malloc的区别
- 6-2 vulnerability exploitation - inevitable problems of FTP
- [IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
- MPLS experiment operation
- 如何用一款产品推动「品牌的惊险一跃」?
- Modeling essays series 124 a simple coding method
- Edge computing accelerates live video scenes: clearer, smoother, and more real-time
- 734. Energy stone (greed, backpack)
- 2022 Q2 - 提升技能的技巧总结
- NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
猜你喜欢

Matlab uses resample to complete resampling

What is AQS and its principle

2022年6月国产数据库大事记

Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)

Edge computing accelerates live video scenes: clearer, smoother, and more real-time

This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable

The role of artificial intelligence in network security

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park

Android high frequency network interview topic must know and be able to compare Android development environment

PR second training
随机推荐
Exclusive delivery of secret script move disassembly (the first time)
matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
SQLite 3 of embedded database
机器学习基本概念
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
2022 Q2 - 提升技能的技巧总结
Ks006 student achievement management system based on SSM
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
人工智能在网络安全中的作用
Cross domain? Homology? Understand what is cross domain at once
Learn basic K-line diagram knowledge in three minutes
6-3 vulnerability exploitation SSH environment construction
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Learn C language from scratch day 025 (maze)
GL Studio 5 installation and experience
MPLS experiment operation
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Makefile simple induction
Leetcode, 3 repeatless longest subsequence
电子协会 C语言 1级 33 、奇偶数判断