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 中连接字符串?


基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在多列上分布任意行 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01