当前位置:网站首页>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列转行函数指的是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
边栏推荐
- D discard the virtual recovery method
- [Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
- Ks006 student achievement management system based on SSM
- 1222. Password dropping (interval DP, bracket matching)
- Exclusive delivery of secret script move disassembly (the first time)
- Three core problems of concurrent programming
- Modeling essays series 124 a simple coding method
- Experimental reproduction of variable image compression with a scale hyperprior
- Selection of field types for creating tables in MySQL database
- Learn basic K-line diagram knowledge in three minutes
猜你喜欢

matlab 实现语音信号重采样和归一化,并播放比对效果

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

微信小程序中使用tabBar

734. Energy stone (greed, backpack)

基于SSM实现微博系统
![[IVX junior engineer training course 10 papers] 06 database and services](/img/68/967566fc2f1d0b93ecd78bdb208b64.jpg)
[IVX junior engineer training course 10 papers] 06 database and services

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

Implementation of Weibo system based on SSM

并发编程的三大核心问题

Game thinking 15: thinking about the whole region and sub region Services
随机推荐
734. Energy stone (greed, backpack)
Failed to transform file 'xxx' to match attributes
牛客网——华为题库(51~60)
1069. Division of convex polygons (thinking, interval DP)
Three core problems of concurrent programming
浅浅了解Servlet
医药管理系统(大一下C语言课设)
uTools
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
Have you stepped on the nine common pits in the e-commerce system?
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
How to use a product to promote "brand thrill"?
[Maya] the error of importing Maya into Metahuman
6-3 vulnerability exploitation SSH environment construction
Number of palindromes in C language (leetcode)
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
企业应该选择无服务器计算吗?
We should make clear the branch prediction
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?