当前位置:网站首页>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列转行函数指的是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
边栏推荐
- 微信小程序中使用tabBar
- 6-2漏洞利用-ftp不可避免的问题
- This is the form of the K-line diagram (pithy formula)
- Altium designer measure distance (ctrl+m)
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- 开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
- The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
- Number of palindromes in C language (leetcode)
- Unity AssetBundle subcontracting
- D discard the virtual recovery method
猜你喜欢

Learning note 24 - multi sensor post fusion technology

II Basic structure of radio energy transmission system

k线图形态这样记(口诀篇)

Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound

How to use a product to promote "brand thrill"?

Should enterprises choose server free computing?

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

TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
![[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me](/img/b8/31a498c89cf96567640677e859df4e.jpg)
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me

Raspberry pie 4B learning notes - IO communication (1-wire)
随机推荐
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Laravel artisan common commands
Unity AssetBundle subcontracting
The role of artificial intelligence in network security
【LeetCode 43】236. The nearest common ancestor of binary tree
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
三分钟学会基础k线图知识
np. Where and torch Where usage
Android high frequency network interview topic must know and be able to compare Android development environment
人工智能在网络安全中的作用
Should enterprises choose server free computing?
Four basic strategies for migrating cloud computing workloads
What is AQS and its principle
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
479. Additive binary tree (interval DP on the tree)
遊戲思考15:全區全服和分區分服的思考
Altium designer measure distance (ctrl+m)
Learn about servlets
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
Penser au jeu 15: penser au service complet et au sous - service