当前位置:网站首页>What is the MySQL column to row function
What is the MySQL column to row function
2022-07-02 01:55:00 【Yisu cloud】
mysql What does the column to row function mean
This article mainly explains “mysql What does the column to row function mean ”, The explanation in the text is simple and clear , Easy to learn and understand , Next, please follow Xiaobian's ideas and go deeper slowly , Study and learn together “mysql What does the column to row function mean ” Well !
stay mysql in , The column to row function is “group_concat()” function ; This function is used to merge non empty column values according to grouping conditions and finally return , If there is a null value, the returned result is null , The grammar is “select group_concat(name separator ';') Name from Table name ;”.
The operating environment of this tutorial :windows10 System 、mysql8.0.22 edition 、Dell G3 The computer .
mysql What is the column to row function
GROUP_CONCAT(expr) This function combines the non empty column values according to the grouping conditions and finally returns . If there is a null value , Then return to empty
stay MySQL in , How to turn a column into a row ? For example, a commodity will belong to multiple categories ( For example, Huawei mobile phones can be classified as mobile phones , It can also be digital classification ), How to show all categories of this commodity in one piece of data .
The idea is simple , adopt MySQL function group_concat Can solve .
Create test table :
create table test.test_mysql_liezhuanhang (id bigint auto_increment comment ' Primary key ',name varchar(100),age int(5),primary key (id))engine=innodb default charset=utf8mb4 comment=' The test table '
Import test data :
insert into test.test_mysql_liezhuanhang (name, age) values (' Li Wei ', 18), (' Li Wei ', 19), (' Li Wei ', 18), (' Li Bai ', 20), (' Li Bai ', 20), (' Li Bai ', 19);
Show all names , Divide by semicolon , Default to ,
Division
select group_concat(name separator ';') concat from test.test_mysql_liezhuanhang ;
Show all names , And duplicate the same name
select group_concat(distinct name) concat from test.test_mysql_liezhuanhang ;
Show all ages , De duplication and sort in ascending order of age
select group_concat(distinct age order by age) concat from test.test_mysql_liezhuanhang ;
Thank you for reading , That's all “mysql What does the column to row function mean ” Content. , After learning this article , I'm sure you're right mysql We have a deeper understanding of what the column to row function refers to , The specific use needs to be verified by practice . This is billion speed cloud , Xiaobian will push you articles with more relevant knowledge points , Welcome to your attention !
边栏推荐
- The technology boss is ready, and the topic of position C is up to you
- PR second training
- Construction and maintenance of business websites [14]
- What are the skills of spot gold analysis?
- 基于SSM实现微博系统
- leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
- uTools
- Five skills of adding audio codec to embedded system
- 6-2 vulnerability exploitation - inevitable problems of FTP
- JMeter (II) - install the custom thread groups plug-in
猜你喜欢
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Cross domain? Homology? Understand what is cross domain at once
Using tabbar in wechat applet
Penser au jeu 15: penser au service complet et au sous - service
The concept, function, characteristics, creation and deletion of MySQL constraints
遷移雲計算工作負載的四個基本策略
企业应该选择无服务器计算吗?
matlab 实现语音信号重采样和归一化,并播放比对效果
Feature extraction and detection 16 brisk feature detection and matching
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
随机推荐
基于SSM实现微博系统
Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
5g/4g pole gateway_ Smart pole gateway
Feature extraction and detection 16 brisk feature detection and matching
2022 Q2 - Summary of skills to improve skills
The technology boss is ready, and the topic of position C is up to you
如何用一款产品推动「品牌的惊险一跃」?
Laravel artisan 常用命令
Six lessons to be learned for the successful implementation of edge coding
电子协会 C语言 1级 33 、奇偶数判断
Implementation principle of city selector component
The concept, function, characteristics, creation and deletion of MySQL constraints
Learn basic K-line diagram knowledge in three minutes
Construction and maintenance of business websites [10]
Post infiltration flow encryption
Opengauss database backup and recovery guide
【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
321. Chessboard segmentation (2D interval DP)
[question] - why is optical flow not good for static scenes
k线图形态这样记(口诀篇)