How to use GROUP BY to concatenate strings in MySQL?(如何使用 GROUP BY 在 MySQL 中连接字符串?)
问题描述
基本上问题是如何从中获得:
<前>foo_id foo_name1 安1 乙2 C为此:
<前>foo_id foo_name1 甲乙2 CSELECT id, GROUP_CONCAT(name SEPARATOR ' ') FROM table GROUP BY id;
https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
从上面的链接,GROUP_CONCAT
:此函数返回一个字符串结果,其中包含来自组的连接的非 NULL 值.如果没有非 NULL 值,则返回 NULL.
Basically the question is how to get from this:
foo_id foo_name 1 A 1 B 2 C
to this:
foo_id foo_name 1 A B 2 C
SELECT id, GROUP_CONCAT(name SEPARATOR ' ') FROM table GROUP BY id;
https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
From the link above, GROUP_CONCAT
: This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.
这篇关于如何使用 GROUP BY 在 MySQL 中连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 GROUP BY 在 MySQL 中连接字符串?


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01